Wednesday, 11 September 2019

Creating an NDEF WiFi Record using application/vnd.wfa.wsc in Swift

I'm trying to create a application/vnd.wfa.wsc payload in Swift. I found this post here for Android: Creating an NDEF WiFi record using application/vnd.wfa.wsc in Android

I'm stuck with creating the payload that I want to write on a NFC Tag. I tried to translate the java code to swift and wrote the payload on an NFC Tag but I'm not able to read the data with an android phone.

let VERSION: [UInt8] = [0x10, 0x4A]
let CREDENTIAL: [UInt8] = [0x10, 0x0e]
let AUTH_TYPE: [UInt8]    = [0x10, 0x03]
let CRYPT_TYPE: [UInt8]   = [0x10, 0x0F]
let MAC_ADDRESS: [UInt8]  = [0x10, 0x20]
let NETWORK_IDX: [UInt8]  = [0x10, 0x26]
let NETWORK_KEY: [UInt8]  = [0x10, 0x27]
let NETWORK_NAME: [UInt8] = [0x10, 0x45]
let OOB_PASSWORD: [UInt8] = [0x10, 0x2C]
let VENDOR_EXT: [UInt8]   = [0x10, 0x49]
let VENDOR_WFA: [UInt8]   = [0x00, 0x37, 0x2A]
let VERSION2: [UInt8]     = [0x00]
let KEY_SHAREABLE: [UInt8] = [0x02]
let AUTH_OPEN: [UInt8] = [0x00, 0x01]
let AUTH_WPA_PERSONAL: [UInt8] = [0x00, 0x02]
let AUTH_SHARED: [UInt8] = [0x00, 0x04]
let AUTH_WPA_ENTERPRISE: [UInt8] = [0x00, 0x08]
let AUTH_WPA2_ENTERPRISE: [UInt8] = [0x00, 0x10]
let AUTH_WPA2_PERSONAL: [UInt8] = [0x00, 0x20]
let AUTH_WPA_WPA2_PERSONAL: [UInt8] = [0x00, 0x22]
let CRYPT_NONE: [UInt8] = [0x00, 0x01]
let CRYPT_WEP: [UInt8] = [0x00, 0x02]
let CRYPT_TKIP: [UInt8] = [0x00, 0x04]
let CRYPT_AES: [UInt8] = [0x00, 0x08]
let CRYPT_AES_TKIP: [UInt8] = [0x00, 0x0C]

let credential: [UInt8] = [0x00, 0x36]
let idx: [UInt8] = [0x00, 0x01, 0x01]

let ssid = "TestWifi"
let password = "Test12345"

let ssidBytes: [UInt8] = Array(ssid.utf8)
let passwordBytes: [UInt8] = Array(password.utf8)
let authBytes: [UInt8] = Array("WPA PSK".utf8)

let lengthSSID: [UInt8] = [UInt8(ssid.lengthOfBytes(using: .utf8))]
let lengthPassword: [UInt8] = [UInt8(password.lengthOfBytes(using: .utf8))]

let cred: [UInt8] = CREDENTIAL + credential
let index: [UInt8] = NETWORK_IDX + idx
let network: [UInt8] = NETWORK_NAME + lengthSSID + ssidBytes
let auth: [UInt8] = AUTH_TYPE + AUTH_WPA_PERSONAL + authBytes
let crypt: [UInt8] = CRYPT_TYPE + CRYPT_WEP + CRYPT_AES_TKIP
let netw: [UInt8] = NETWORK_KEY + lengthPassword + passwordBytes

let foo1 = cred + index
let foo2 = network + auth
let foo3 = crypt + netw

let payload = foo1 + foo2 + foo3


Can someone point out what I'm doing wrong?



from Creating an NDEF WiFi Record using application/vnd.wfa.wsc in Swift

No comments:

Post a Comment