ios - Unable to convert NSData to NSString or any other format of informationElementData of CWNetwork -


friends,

it might familiar question need convert nsdata other understandable form. using corewlan framework , cwnetwork has called informationelement , it's data type nsdata. have tried convert other readable format not working. have tried available string encoding. below sample code:

- (void) printnsdata:(nsdata *) datatoprint forkey:(nsstring *) key{     for(int = 1 ; < 16 ; i++){                size_t length = [datatoprint length]+1;         unsigned char abuffer[length];         [datatoprint getbytes:abuffer length:length];         abuffer[length] = 0;         nsstring *content = [[nsstring alloc]  initwithbytes:abuffer                                                       length:[datatoprint length] encoding: i];         nslog(@"%@ : %@ ", key,content);     }     /*     nsutf16bigendianstringencoding = 0x90000100,     nsutf16littleendianstringencoding = 0x94000100,     nsutf32stringencoding = 0x8c000100,     nsutf32bigendianstringencoding = 0x98000100,     nsutf32littleendianstringencoding = 0x9c000100,     nsproprietarystringencoding = 65536      */     nsstring *content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                                   length:[datatoprint length] encoding: nsutf16bigendianstringencoding];     nslog(@"%@ : %@ ",key, content);     content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                         length:[datatoprint length] encoding: nsutf16littleendianstringencoding];     nslog(@"%@ : %@ ",key, content);      content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                         length:[datatoprint length] encoding: nsutf32stringencoding];     nslog(@"%@ : %@ ", key,content);      content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                         length:[datatoprint length] encoding: nsutf32bigendianstringencoding];     nslog(@"%@ : %@ ", key,content);      content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                         length:[datatoprint length] encoding: nsutf32littleendianstringencoding];     nslog(@"%@ : %@ ", key,content);      content = [[nsstring alloc]  initwithbytes:[datatoprint bytes]                                         length:[datatoprint length] encoding: nsproprietarystringencoding];     nslog(@"%@ : %@", key,content);  } 

but getting either null or empty response. please please help.

regards, mp

you can't convert arbitrary data string. works data represents string. not case if api exposes nsdata object.

to meaning data have know data represents.

you might able structure looking @ it.
if @ first few bytes have posted looks data structured , not arbitrary.

the data seams split packets. each packet starts type identifier, followed $length byte. , there $length bytes of data

the first packet contains string "symantak"

00 08 53 79 6d 61 6e 74 61 6b ^^ type identifier    ^^ length       ^^^^^^^^^^^^^^^^^^^^^^^ data. in case ascii string "symantak" 

if find bunch of bytes lay between 0x20 , 0x7e looking @ ascii. that's how figured out payload of packet. , because have 8 bytes ascii 0x08 in front of ascii means 8 bytes of data.

the next packets this:

01 08 82 84 0b 16 24 30 48 6c ^^ type identifier    ^^ length       ^^^^^^^^^^^^^^^^^^^^^^^ data. not ascii string 03 01 06 2a 01 00 2f 01 00 30 14 01 00 00 0f ac 04 01 00 00 0f ac 04 01 00 00 0f ac 02 0c 00  32 04 0c 12 18 60  2d 1a 6e 18 1b ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

and on. general packet structure quite easy parse.
though hard turn these bytes meaningful data. can see other packets, it's not easy first packet contained ascii.

but please don't take reverse engineered structure granted. might wrong meaning of these fields.

you should try find specification of data. should somewhere in ieee 802.11 documents.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -