Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[deliverable/linux.git] / drivers / staging / wilc1000 / coreconfigurator.c
1
2 /*!
3 * @file coreconfigurator.c
4 * @brief
5 * @author
6 * @sa coreconfigurator.h
7 * @date 1 Mar 2012
8 * @version 1.0
9 */
10
11
12 /*****************************************************************************/
13 /* File Includes */
14 /*****************************************************************************/
15 #include "coreconfigurator.h"
16 /*****************************************************************************/
17 /* Constants */
18 /*****************************************************************************/
19 #define INLINE static __inline
20 #define PHY_802_11n
21 #define MAX_CFG_PKTLEN 1450
22 #define MSG_HEADER_LEN 4
23 #define QUERY_MSG_TYPE 'Q'
24 #define WRITE_MSG_TYPE 'W'
25 #define RESP_MSG_TYPE 'R'
26 #define WRITE_RESP_SUCCESS 1
27 #define INVALID 255
28 #define MAC_ADDR_LEN 6
29 #define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
30 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
31
32 /*****************************************************************************/
33 /* Function Macros */
34 /*****************************************************************************/
35
36
37 /*****************************************************************************/
38 /* Type Definitions */
39 /*****************************************************************************/
40
41 /* Basic Frame Type Codes (2-bit) */
42 typedef enum {
43 FRAME_TYPE_CONTROL = 0x04,
44 FRAME_TYPE_DATA = 0x08,
45 FRAME_TYPE_MANAGEMENT = 0x00,
46 FRAME_TYPE_RESERVED = 0x0C,
47 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
48 } tenuBasicFrmType;
49
50 /* Frame Type and Subtype Codes (6-bit) */
51 typedef enum {
52 ASSOC_REQ = 0x00,
53 ASSOC_RSP = 0x10,
54 REASSOC_REQ = 0x20,
55 REASSOC_RSP = 0x30,
56 PROBE_REQ = 0x40,
57 PROBE_RSP = 0x50,
58 BEACON = 0x80,
59 ATIM = 0x90,
60 DISASOC = 0xA0,
61 AUTH = 0xB0,
62 DEAUTH = 0xC0,
63 ACTION = 0xD0,
64 PS_POLL = 0xA4,
65 RTS = 0xB4,
66 CTS = 0xC4,
67 ACK = 0xD4,
68 CFEND = 0xE4,
69 CFEND_ACK = 0xF4,
70 DATA = 0x08,
71 DATA_ACK = 0x18,
72 DATA_POLL = 0x28,
73 DATA_POLL_ACK = 0x38,
74 NULL_FRAME = 0x48,
75 CFACK = 0x58,
76 CFPOLL = 0x68,
77 CFPOLL_ACK = 0x78,
78 QOS_DATA = 0x88,
79 QOS_DATA_ACK = 0x98,
80 QOS_DATA_POLL = 0xA8,
81 QOS_DATA_POLL_ACK = 0xB8,
82 QOS_NULL_FRAME = 0xC8,
83 QOS_CFPOLL = 0xE8,
84 QOS_CFPOLL_ACK = 0xF8,
85 BLOCKACK_REQ = 0x84,
86 BLOCKACK = 0x94,
87 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
88 } tenuFrmSubtype;
89
90 /* Basic Frame Classes */
91 typedef enum {
92 CLASS1_FRAME_TYPE = 0x00,
93 CLASS2_FRAME_TYPE = 0x01,
94 CLASS3_FRAME_TYPE = 0x02,
95 FRAME_CLASS_FORCE_32BIT = 0xFFFFFFFF
96 } tenuFrameClass;
97
98 /* Element ID of various Information Elements */
99 typedef enum {
100 ISSID = 0, /* Service Set Identifier */
101 ISUPRATES = 1, /* Supported Rates */
102 IFHPARMS = 2, /* FH parameter set */
103 IDSPARMS = 3, /* DS parameter set */
104 ICFPARMS = 4, /* CF parameter set */
105 ITIM = 5, /* Traffic Information Map */
106 IIBPARMS = 6, /* IBSS parameter set */
107 ICOUNTRY = 7, /* Country element */
108 IEDCAPARAMS = 12, /* EDCA parameter set */
109 ITSPEC = 13, /* Traffic Specification */
110 ITCLAS = 14, /* Traffic Classification */
111 ISCHED = 15, /* Schedule */
112 ICTEXT = 16, /* Challenge Text */
113 IPOWERCONSTRAINT = 32, /* Power Constraint */
114 IPOWERCAPABILITY = 33, /* Power Capability */
115 ITPCREQUEST = 34, /* TPC Request */
116 ITPCREPORT = 35, /* TPC Report */
117 ISUPCHANNEL = 36, /* Supported channel list */
118 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
119 IMEASUREMENTREQUEST = 38, /* Measurement request */
120 IMEASUREMENTREPORT = 39, /* Measurement report */
121 IQUIET = 40, /* Quiet element Info */
122 IIBSSDFS = 41, /* IBSS DFS */
123 IERPINFO = 42, /* ERP Information */
124 ITSDELAY = 43, /* TS Delay */
125 ITCLASPROCESS = 44, /* TCLAS Processing */
126 IHTCAP = 45, /* HT Capabilities */
127 IQOSCAP = 46, /* QoS Capability */
128 IRSNELEMENT = 48, /* RSN Information Element */
129 IEXSUPRATES = 50, /* Extended Supported Rates */
130 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
131 IHTOPERATION = 61, /* HT Information */
132 ISECCHOFF = 62, /* Secondary Channel Offeset */
133 I2040COEX = 72, /* 20/40 Coexistence IE */
134 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
135 IOBSSSCAN = 74, /* OBSS Scan parameters */
136 IEXTCAP = 127, /* Extended capability */
137 IWMM = 221, /* WMM parameters */
138 IWPAELEMENT = 221, /* WPA Information Element */
139 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
140 } tenuInfoElemID;
141
142
143 typedef struct {
144 char *pcRespBuffer;
145 s32 s32MaxRespBuffLen;
146 s32 s32BytesRead;
147 bool bRespRequired;
148 } tstrConfigPktInfo;
149
150
151
152 /*****************************************************************************/
153 /* Extern Variable Declarations */
154 /*****************************************************************************/
155
156
157 /*****************************************************************************/
158 /* Extern Function Declarations */
159 /*****************************************************************************/
160 extern s32 SendRawPacket(s8 *ps8Packet, s32 s32PacketLen);
161 extern void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length);
162 extern void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length);
163 extern void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length);
164 /*****************************************************************************/
165 /* Global Variables */
166 /*****************************************************************************/
167 static struct semaphore SemHandleSendPkt;
168 static struct semaphore SemHandlePktResp;
169
170 static s8 *gps8ConfigPacket;
171
172 static tstrConfigPktInfo gstrConfigPktInfo;
173
174 static u8 g_seqno;
175
176 static s16 g_wid_num = -1;
177
178 static u16 Res_Len;
179
180 static u8 g_oper_mode = SET_CFG;
181
182 /* WID Switches */
183 static tstrWID gastrWIDs[] = {
184 {WID_FIRMWARE_VERSION, WID_STR},
185 {WID_PHY_VERSION, WID_STR},
186 {WID_HARDWARE_VERSION, WID_STR},
187 {WID_BSS_TYPE, WID_CHAR},
188 {WID_QOS_ENABLE, WID_CHAR},
189 {WID_11I_MODE, WID_CHAR},
190 {WID_CURRENT_TX_RATE, WID_CHAR},
191 {WID_LINKSPEED, WID_CHAR},
192 {WID_RTS_THRESHOLD, WID_SHORT},
193 {WID_FRAG_THRESHOLD, WID_SHORT},
194 {WID_SSID, WID_STR},
195 {WID_BSSID, WID_ADR},
196 {WID_BEACON_INTERVAL, WID_SHORT},
197 {WID_POWER_MANAGEMENT, WID_CHAR},
198 {WID_LISTEN_INTERVAL, WID_CHAR},
199 {WID_DTIM_PERIOD, WID_CHAR},
200 {WID_CURRENT_CHANNEL, WID_CHAR},
201 {WID_TX_POWER_LEVEL_11A, WID_CHAR},
202 {WID_TX_POWER_LEVEL_11B, WID_CHAR},
203 {WID_PREAMBLE, WID_CHAR},
204 {WID_11G_OPERATING_MODE, WID_CHAR},
205 {WID_MAC_ADDR, WID_ADR},
206 {WID_IP_ADDRESS, WID_ADR},
207 {WID_ACK_POLICY, WID_CHAR},
208 {WID_PHY_ACTIVE_REG, WID_CHAR},
209 {WID_AUTH_TYPE, WID_CHAR},
210 {WID_REKEY_POLICY, WID_CHAR},
211 {WID_REKEY_PERIOD, WID_INT},
212 {WID_REKEY_PACKET_COUNT, WID_INT},
213 {WID_11I_PSK, WID_STR},
214 {WID_1X_KEY, WID_STR},
215 {WID_1X_SERV_ADDR, WID_IP},
216 {WID_SUPP_USERNAME, WID_STR},
217 {WID_SUPP_PASSWORD, WID_STR},
218 {WID_USER_CONTROL_ON_TX_POWER, WID_CHAR},
219 {WID_MEMORY_ADDRESS, WID_INT},
220 {WID_MEMORY_ACCESS_32BIT, WID_INT},
221 {WID_MEMORY_ACCESS_16BIT, WID_SHORT},
222 {WID_MEMORY_ACCESS_8BIT, WID_CHAR},
223 {WID_SITE_SURVEY_RESULTS, WID_STR},
224 {WID_PMKID_INFO, WID_STR},
225 {WID_ASSOC_RES_INFO, WID_STR},
226 {WID_MANUFACTURER, WID_STR}, /* 4 Wids added for the CAPI tool*/
227 {WID_MODEL_NAME, WID_STR},
228 {WID_MODEL_NUM, WID_STR},
229 {WID_DEVICE_NAME, WID_STR},
230 {WID_SSID_PROBE_REQ, WID_STR},
231
232 #ifdef MAC_802_11N
233 {WID_11N_ENABLE, WID_CHAR},
234 {WID_11N_CURRENT_TX_MCS, WID_CHAR},
235 {WID_TX_POWER_LEVEL_11N, WID_CHAR},
236 {WID_11N_OPERATING_MODE, WID_CHAR},
237 {WID_11N_SMPS_MODE, WID_CHAR},
238 {WID_11N_PROT_MECH, WID_CHAR},
239 {WID_11N_ERP_PROT_TYPE, WID_CHAR},
240 {WID_11N_HT_PROT_TYPE, WID_CHAR},
241 {WID_11N_PHY_ACTIVE_REG_VAL, WID_INT},
242 {WID_11N_PRINT_STATS, WID_CHAR},
243 {WID_11N_AUTORATE_TABLE, WID_BIN_DATA},
244 {WID_HOST_CONFIG_IF_TYPE, WID_CHAR},
245 {WID_HOST_DATA_IF_TYPE, WID_CHAR},
246 {WID_11N_SIG_QUAL_VAL, WID_SHORT},
247 {WID_11N_IMMEDIATE_BA_ENABLED, WID_CHAR},
248 {WID_11N_TXOP_PROT_DISABLE, WID_CHAR},
249 {WID_11N_SHORT_GI_20MHZ_ENABLE, WID_CHAR},
250 {WID_SHORT_SLOT_ALLOWED, WID_CHAR},
251 {WID_11W_ENABLE, WID_CHAR},
252 {WID_11W_MGMT_PROT_REQ, WID_CHAR},
253 {WID_2040_ENABLE, WID_CHAR},
254 {WID_2040_COEXISTENCE, WID_CHAR},
255 {WID_USER_SEC_CHANNEL_OFFSET, WID_CHAR},
256 {WID_2040_CURR_CHANNEL_OFFSET, WID_CHAR},
257 {WID_2040_40MHZ_INTOLERANT, WID_CHAR},
258 {WID_HUT_RESTART, WID_CHAR},
259 {WID_HUT_NUM_TX_PKTS, WID_INT},
260 {WID_HUT_FRAME_LEN, WID_SHORT},
261 {WID_HUT_TX_FORMAT, WID_CHAR},
262 {WID_HUT_BANDWIDTH, WID_CHAR},
263 {WID_HUT_OP_BAND, WID_CHAR},
264 {WID_HUT_STBC, WID_CHAR},
265 {WID_HUT_ESS, WID_CHAR},
266 {WID_HUT_ANTSET, WID_CHAR},
267 {WID_HUT_HT_OP_MODE, WID_CHAR},
268 {WID_HUT_RIFS_MODE, WID_CHAR},
269 {WID_HUT_SMOOTHING_REC, WID_CHAR},
270 {WID_HUT_SOUNDING_PKT, WID_CHAR},
271 {WID_HUT_HT_CODING, WID_CHAR},
272 {WID_HUT_TEST_DIR, WID_CHAR},
273 {WID_HUT_TXOP_LIMIT, WID_SHORT},
274 {WID_HUT_DEST_ADDR, WID_ADR},
275 {WID_HUT_TX_PATTERN, WID_BIN_DATA},
276 {WID_HUT_TX_TIME_TAKEN, WID_INT},
277 {WID_HUT_PHY_TEST_MODE, WID_CHAR},
278 {WID_HUT_PHY_TEST_RATE_HI, WID_CHAR},
279 {WID_HUT_PHY_TEST_RATE_LO, WID_CHAR},
280 {WID_HUT_TX_TEST_TIME, WID_INT},
281 {WID_HUT_LOG_INTERVAL, WID_INT},
282 {WID_HUT_DISABLE_RXQ_REPLENISH, WID_CHAR},
283 {WID_HUT_TEST_ID, WID_STR},
284 {WID_HUT_KEY_ORIGIN, WID_CHAR},
285 {WID_HUT_BCST_PERCENT, WID_CHAR},
286 {WID_HUT_GROUP_CIPHER_TYPE, WID_CHAR},
287 {WID_HUT_STATS, WID_BIN_DATA},
288 {WID_HUT_TSF_TEST_MODE, WID_CHAR},
289 {WID_HUT_SIG_QUAL_AVG, WID_SHORT},
290 {WID_HUT_SIG_QUAL_AVG_CNT, WID_SHORT},
291 {WID_HUT_TSSI_VALUE, WID_CHAR},
292 {WID_HUT_MGMT_PERCENT, WID_CHAR},
293 {WID_HUT_MGMT_BCST_PERCENT, WID_CHAR},
294 {WID_HUT_MGMT_ALLOW_HT, WID_CHAR},
295 {WID_HUT_UC_MGMT_TYPE, WID_CHAR},
296 {WID_HUT_BC_MGMT_TYPE, WID_CHAR},
297 {WID_HUT_UC_MGMT_FRAME_LEN, WID_SHORT},
298 {WID_HUT_BC_MGMT_FRAME_LEN, WID_SHORT},
299 {WID_HUT_11W_MFP_REQUIRED_TX, WID_CHAR},
300 {WID_HUT_11W_MFP_PEER_CAPABLE, WID_CHAR},
301 {WID_HUT_11W_TX_IGTK_ID, WID_CHAR},
302 {WID_HUT_FC_TXOP_MOD, WID_CHAR},
303 {WID_HUT_FC_PROT_TYPE, WID_CHAR},
304 {WID_HUT_SEC_CCA_ASSERT, WID_CHAR},
305 #endif /* MAC_802_11N */
306 };
307
308 u16 g_num_total_switches = (sizeof(gastrWIDs) / sizeof(tstrWID));
309 /*****************************************************************************/
310 /* Static Function Declarations */
311 /*****************************************************************************/
312
313
314
315 /*****************************************************************************/
316 /* Functions */
317 /*****************************************************************************/
318 INLINE u8 ascii_hex_to_dec(u8 num)
319 {
320 if ((num >= '0') && (num <= '9'))
321 return (num - '0');
322 else if ((num >= 'A') && (num <= 'F'))
323 return (10 + (num - 'A'));
324 else if ((num >= 'a') && (num <= 'f'))
325 return (10 + (num - 'a'));
326
327 return INVALID;
328 }
329
330 INLINE u8 get_hex_char(u8 inp)
331 {
332 u8 *d2htab = "0123456789ABCDEF";
333
334 return d2htab[inp & 0xF];
335 }
336
337 /* This function extracts the MAC address held in a string in standard format */
338 /* into another buffer as integers. */
339 INLINE u16 extract_mac_addr(char *str, u8 *buff)
340 {
341 *buff = 0;
342 while (*str != '\0') {
343 if ((*str == ':') || (*str == '-'))
344 *(++buff) = 0;
345 else
346 *buff = (*buff << 4) + ascii_hex_to_dec(*str);
347
348 str++;
349 }
350
351 return MAC_ADDR_LEN;
352 }
353
354 /* This function creates MAC address in standard format from a buffer of */
355 /* integers. */
356 INLINE void create_mac_addr(u8 *str, u8 *buff)
357 {
358 u32 i = 0;
359 u32 j = 0;
360
361 for (i = 0; i < MAC_ADDR_LEN; i++) {
362 str[j++] = get_hex_char((u8)((buff[i] >> 4) & 0x0F));
363 str[j++] = get_hex_char((u8)(buff[i] & 0x0F));
364 str[j++] = ':';
365 }
366 str[--j] = '\0';
367 }
368
369 /* This function converts the IP address string in dotted decimal format to */
370 /* unsigned integer. This functionality is similar to the library function */
371 /* inet_addr() but is reimplemented here since I could not confirm that */
372 /* inet_addr is platform independent. */
373 /* ips=>IP Address String in dotted decimal format */
374 /* ipn=>Pointer to IP Address in integer format */
375 INLINE u8 conv_ip_to_int(u8 *ips, u32 *ipn)
376 {
377 u8 i = 0;
378 u8 ipb = 0;
379 *ipn = 0;
380 /* Integer to string for each component */
381 while (ips[i] != '\0') {
382 if (ips[i] == '.') {
383 *ipn = ((*ipn) << 8) | ipb;
384 ipb = 0;
385 } else {
386 ipb = ipb * 10 + ascii_hex_to_dec(ips[i]);
387 }
388
389 i++;
390 }
391
392 /* The last byte of the IP address is read in here */
393 *ipn = ((*ipn) << 8) | ipb;
394
395 return 0;
396 }
397
398 /* This function converts the IP address from integer format to dotted */
399 /* decimal string format. Alternative to std library fn inet_ntoa(). */
400 /* ips=>Buffer to hold IP Address String dotted decimal format (Min 17B) */
401 /* ipn=>IP Address in integer format */
402 INLINE u8 conv_int_to_ip(u8 *ips, u32 ipn)
403 {
404 u8 i = 0;
405 u8 ipb = 0;
406 u8 cnt = 0;
407 u8 ipbsize = 0;
408
409 for (cnt = 4; cnt > 0; cnt--) {
410 ipb = (ipn >> (8 * (cnt - 1))) & 0xFF;
411
412 if (ipb >= 100)
413 ipbsize = 2;
414 else if (ipb >= 10)
415 ipbsize = 1;
416 else
417 ipbsize = 0;
418
419 switch (ipbsize) {
420 case 2:
421 ips[i++] = get_hex_char(ipb / 100);
422 ipb %= 100;
423
424 case 1:
425 ips[i++] = get_hex_char(ipb / 10);
426 ipb %= 10;
427
428 default:
429 ips[i++] = get_hex_char(ipb);
430 }
431
432 if (cnt > 1)
433 ips[i++] = '.';
434 }
435
436 ips[i] = '\0';
437
438 return i;
439 }
440
441 INLINE tenuWIDtype get_wid_type(u32 wid_num)
442 {
443 /* Check for iconfig specific WID types first */
444 if ((wid_num == WID_BSSID) ||
445 (wid_num == WID_MAC_ADDR) ||
446 (wid_num == WID_IP_ADDRESS) ||
447 (wid_num == WID_HUT_DEST_ADDR)) {
448 return WID_ADR;
449 }
450
451 if ((WID_1X_SERV_ADDR == wid_num) ||
452 (WID_STACK_IP_ADDR == wid_num) ||
453 (WID_STACK_NETMASK_ADDR == wid_num)) {
454 return WID_IP;
455 }
456
457 /* Next check for standard WID types */
458 if (wid_num < 0x1000)
459 return WID_CHAR;
460 else if (wid_num < 0x2000)
461 return WID_SHORT;
462 else if (wid_num < 0x3000)
463 return WID_INT;
464 else if (wid_num < 0x4000)
465 return WID_STR;
466 else if (wid_num < 0x5000)
467 return WID_BIN_DATA;
468
469 return WID_UNDEF;
470 }
471
472
473 /* This function extracts the beacon period field from the beacon or probe */
474 /* response frame. */
475 INLINE u16 get_beacon_period(u8 *data)
476 {
477 u16 bcn_per = 0;
478
479 bcn_per = data[0];
480 bcn_per |= (data[1] << 8);
481
482 return bcn_per;
483 }
484
485 INLINE u32 get_beacon_timestamp_lo(u8 *data)
486 {
487 u32 time_stamp = 0;
488 u32 index = MAC_HDR_LEN;
489
490 time_stamp |= data[index++];
491 time_stamp |= (data[index++] << 8);
492 time_stamp |= (data[index++] << 16);
493 time_stamp |= (data[index] << 24);
494
495 return time_stamp;
496 }
497
498 INLINE u32 get_beacon_timestamp_hi(u8 *data)
499 {
500 u32 time_stamp = 0;
501 u32 index = (MAC_HDR_LEN + 4);
502
503 time_stamp |= data[index++];
504 time_stamp |= (data[index++] << 8);
505 time_stamp |= (data[index++] << 16);
506 time_stamp |= (data[index] << 24);
507
508 return time_stamp;
509 }
510
511 /* This function extracts the 'frame type' bits from the MAC header of the */
512 /* input frame. */
513 /* Returns the value in the LSB of the returned value. */
514 INLINE tenuBasicFrmType get_type(u8 *header)
515 {
516 return ((tenuBasicFrmType)(header[0] & 0x0C));
517 }
518
519 /* This function extracts the 'frame type and sub type' bits from the MAC */
520 /* header of the input frame. */
521 /* Returns the value in the LSB of the returned value. */
522 INLINE tenuFrmSubtype get_sub_type(u8 *header)
523 {
524 return ((tenuFrmSubtype)(header[0] & 0xFC));
525 }
526
527 /* This function extracts the 'to ds' bit from the MAC header of the input */
528 /* frame. */
529 /* Returns the value in the LSB of the returned value. */
530 INLINE u8 get_to_ds(u8 *header)
531 {
532 return (header[1] & 0x01);
533 }
534
535 /* This function extracts the 'from ds' bit from the MAC header of the input */
536 /* frame. */
537 /* Returns the value in the LSB of the returned value. */
538 INLINE u8 get_from_ds(u8 *header)
539 {
540 return ((header[1] & 0x02) >> 1);
541 }
542
543 /* This function extracts the MAC Address in 'address1' field of the MAC */
544 /* header and updates the MAC Address in the allocated 'addr' variable. */
545 INLINE void get_address1(u8 *pu8msa, u8 *addr)
546 {
547 WILC_memcpy(addr, pu8msa + 4, 6);
548 }
549
550 /* This function extracts the MAC Address in 'address2' field of the MAC */
551 /* header and updates the MAC Address in the allocated 'addr' variable. */
552 INLINE void get_address2(u8 *pu8msa, u8 *addr)
553 {
554 WILC_memcpy(addr, pu8msa + 10, 6);
555 }
556
557 /* This function extracts the MAC Address in 'address3' field of the MAC */
558 /* header and updates the MAC Address in the allocated 'addr' variable. */
559 INLINE void get_address3(u8 *pu8msa, u8 *addr)
560 {
561 WILC_memcpy(addr, pu8msa + 16, 6);
562 }
563
564 /* This function extracts the BSSID from the incoming WLAN packet based on */
565 /* the 'from ds' bit, and updates the MAC Address in the allocated 'addr' */
566 /* variable. */
567 INLINE void get_BSSID(u8 *data, u8 *bssid)
568 {
569 if (get_from_ds(data) == 1)
570 get_address2(data, bssid);
571 else if (get_to_ds(data) == 1)
572 get_address1(data, bssid);
573 else
574 get_address3(data, bssid);
575 }
576
577 /* This function extracts the SSID from a beacon/probe response frame */
578 INLINE void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
579 {
580 u8 len = 0;
581 u8 i = 0;
582 u8 j = 0;
583
584 len = data[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
585 CAP_INFO_LEN + 1];
586 j = MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
587 CAP_INFO_LEN + 2;
588
589 /* If the SSID length field is set wrongly to a value greater than the */
590 /* allowed maximum SSID length limit, reset the length to 0 */
591 if (len >= MAX_SSID_LEN)
592 len = 0;
593
594 for (i = 0; i < len; i++, j++)
595 ssid[i] = data[j];
596
597 ssid[len] = '\0';
598
599 *p_ssid_len = len;
600 }
601
602 /* This function extracts the capability info field from the beacon or probe */
603 /* response frame. */
604 INLINE u16 get_cap_info(u8 *data)
605 {
606 u16 cap_info = 0;
607 u16 index = MAC_HDR_LEN;
608 tenuFrmSubtype st = BEACON;
609
610 st = get_sub_type(data);
611
612 /* Location of the Capability field is different for Beacon and */
613 /* Association frames. */
614 if ((st == BEACON) || (st == PROBE_RSP))
615 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
616
617 cap_info = data[index];
618 cap_info |= (data[index + 1] << 8);
619
620 return cap_info;
621 }
622
623 /* This function extracts the capability info field from the Association */
624 /* response frame. */
625 INLINE u16 get_assoc_resp_cap_info(u8 *data)
626 {
627 u16 cap_info = 0;
628
629 cap_info = data[0];
630 cap_info |= (data[1] << 8);
631
632 return cap_info;
633 }
634
635 /* This funcion extracts the association status code from the incoming */
636 /* association response frame and returns association status code */
637 INLINE u16 get_asoc_status(u8 *data)
638 {
639 u16 asoc_status = 0;
640
641 asoc_status = data[3];
642 asoc_status = (asoc_status << 8) | data[2];
643
644 return asoc_status;
645 }
646
647 /* This function extracts association ID from the incoming association */
648 /* response frame */
649 INLINE u16 get_asoc_id(u8 *data)
650 {
651 u16 asoc_id = 0;
652
653 asoc_id = data[4];
654 asoc_id |= (data[5] << 8);
655
656 return asoc_id;
657 }
658
659 /**
660 * @brief initializes the Core Configurator
661 * @details
662 * @return Error code indicating success/failure
663 * @note
664 * @author mabubakr
665 * @date 1 Mar 2012
666 * @version 1.0
667 */
668
669 s32 CoreConfiguratorInit(void)
670 {
671 s32 s32Error = WILC_SUCCESS;
672 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorInit()\n");
673
674 sema_init(&SemHandleSendPkt, 1);
675 sema_init(&SemHandlePktResp, 0);
676
677 gps8ConfigPacket = (s8 *)WILC_MALLOC(MAX_PACKET_BUFF_SIZE);
678 if (gps8ConfigPacket == NULL) {
679 PRINT_ER("failed in gps8ConfigPacket allocation\n");
680 s32Error = WILC_NO_MEM;
681 goto _fail_;
682 }
683
684 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
685
686 WILC_memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
687 _fail_:
688 return s32Error;
689 }
690
691 u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
692 {
693 u16 u16index = 0;
694
695 /*************************************************************************/
696 /* Beacon Frame - Frame Body */
697 /* --------------------------------------------------------------------- */
698 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
699 /* --------------------------------------------------------------------- */
700 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
701 /* --------------------------------------------------------------------- */
702 /* */
703 /*************************************************************************/
704
705 u16index = u16TagParamOffset;
706
707 /* Search for the TIM Element Field and return if the element is found */
708 while (u16index < (u16RxLen - FCS_LEN)) {
709 if (pu8msa[u16index] == ITIM) {
710 return &pu8msa[u16index];
711 } else {
712 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
713 }
714 }
715
716 return 0;
717 }
718
719 /* This function gets the current channel information from
720 * the 802.11n beacon/probe response frame */
721 u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
722 {
723 u16 index;
724
725 index = TAG_PARAM_OFFSET;
726 while (index < (u16RxLen - FCS_LEN)) {
727 if (pu8msa[index] == IDSPARMS)
728 return pu8msa[index + 2];
729 else
730 /* Increment index by length information and header */
731 index += pu8msa[index + 1] + IE_HDR_LEN;
732 }
733
734 /* Return current channel information from the MIB, if beacon/probe */
735 /* response frame does not contain the DS parameter set IE */
736 /* return (mget_CurrentChannel() + 1); */
737 return 0; /* no MIB here */
738 }
739
740 u8 get_current_channel(u8 *pu8msa, u16 u16RxLen)
741 {
742 #ifdef PHY_802_11n
743 #ifdef FIVE_GHZ_BAND
744 /* Get the current channel as its not set in */
745 /* 802.11a beacons/probe response */
746 return (get_rf_channel() + 1);
747 #else /* FIVE_GHZ_BAND */
748 /* Extract current channel information from */
749 /* the beacon/probe response frame */
750 return get_current_channel_802_11n(pu8msa, u16RxLen);
751 #endif /* FIVE_GHZ_BAND */
752 #else
753 return 0;
754 #endif /* PHY_802_11n */
755 }
756
757 /**
758 * @brief parses the received 'N' message
759 * @details
760 * @param[in] pu8MsgBuffer The message to be parsed
761 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
762 * @return Error code indicating success/failure
763 * @note
764 * @author mabubakr
765 * @date 1 Mar 2012
766 * @version 1.0
767 */
768 s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
769 {
770 s32 s32Error = WILC_SUCCESS;
771 tstrNetworkInfo *pstrNetworkInfo = NULL;
772 u8 u8MsgType = 0;
773 u8 u8MsgID = 0;
774 u16 u16MsgLen = 0;
775
776 u16 u16WidID = (u16)WID_NIL;
777 u16 u16WidLen = 0;
778 u8 *pu8WidVal = 0;
779
780 u8MsgType = pu8MsgBuffer[0];
781
782 /* Check whether the received message type is 'N' */
783 if ('N' != u8MsgType) {
784 PRINT_ER("Received Message format incorrect.\n");
785 WILC_ERRORREPORT(s32Error, WILC_FAIL);
786 }
787
788 /* Extract message ID */
789 u8MsgID = pu8MsgBuffer[1];
790
791 /* Extract message Length */
792 u16MsgLen = MAKE_WORD16(pu8MsgBuffer[2], pu8MsgBuffer[3]);
793
794 /* Extract WID ID */
795 u16WidID = MAKE_WORD16(pu8MsgBuffer[4], pu8MsgBuffer[5]);
796
797 /* Extract WID Length */
798 u16WidLen = MAKE_WORD16(pu8MsgBuffer[6], pu8MsgBuffer[7]);
799
800 /* Assign a pointer to the WID value */
801 pu8WidVal = &pu8MsgBuffer[8];
802
803 /* parse the WID value of the WID "WID_NEWORK_INFO" */
804 {
805 u8 *pu8msa = 0;
806 u16 u16RxLen = 0;
807 u8 *pu8TimElm = 0;
808 u8 *pu8IEs = 0;
809 u16 u16IEsLen = 0;
810 u8 u8index = 0;
811 u32 u32Tsf_Lo;
812 u32 u32Tsf_Hi;
813
814 pstrNetworkInfo = (tstrNetworkInfo *)WILC_MALLOC(sizeof(tstrNetworkInfo));
815 WILC_memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
816
817 pstrNetworkInfo->s8rssi = pu8WidVal[0];
818
819 /* Assign a pointer to msa "Mac Header Start Address" */
820 pu8msa = &pu8WidVal[1];
821
822 u16RxLen = u16WidLen - 1;
823
824 /* parse msa*/
825
826 /* Get the cap_info */
827 pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
828 #ifdef WILC_P2P
829 /* Get time-stamp [Low only 32 bit] */
830 pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
831 PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
832 #endif
833
834 /* Get full time-stamp [Low and High 64 bit] */
835 u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
836 u32Tsf_Hi = get_beacon_timestamp_hi(pu8msa);
837
838 pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
839
840 /* Get SSID */
841 get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &(pstrNetworkInfo->u8SsidLen));
842
843 /* Get BSSID */
844 get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
845
846 /* Get the current channel */
847 pstrNetworkInfo->u8channel = get_current_channel(pu8msa, (u16RxLen + FCS_LEN));
848
849 /* Get beacon period */
850 u8index = (MAC_HDR_LEN + TIME_STAMP_LEN);
851
852 pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
853
854 u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
855
856 /* Get DTIM Period */
857 pu8TimElm = get_tim_elm(pu8msa, (u16RxLen + FCS_LEN), u8index);
858 if (pu8TimElm != 0) {
859 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
860 }
861 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
862 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
863
864 if (u16IEsLen > 0) {
865 pstrNetworkInfo->pu8IEs = (u8 *)WILC_MALLOC(u16IEsLen);
866 WILC_memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
867
868 WILC_memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
869 }
870 pstrNetworkInfo->u16IEsLen = u16IEsLen;
871
872 }
873
874 *ppstrNetworkInfo = pstrNetworkInfo;
875
876 ERRORHANDLER:
877 return s32Error;
878 }
879
880 /**
881 * @brief Deallocates the parsed Network Info
882 * @details
883 * @param[in] pstrNetworkInfo Network Info to be deallocated
884 * @return Error code indicating success/failure
885 * @note
886 * @author mabubakr
887 * @date 1 Mar 2012
888 * @version 1.0
889 */
890 s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
891 {
892 s32 s32Error = WILC_SUCCESS;
893
894 if (pstrNetworkInfo != NULL) {
895 if (pstrNetworkInfo->pu8IEs != NULL) {
896 WILC_FREE(pstrNetworkInfo->pu8IEs);
897 pstrNetworkInfo->pu8IEs = NULL;
898 } else {
899 s32Error = WILC_FAIL;
900 }
901
902 WILC_FREE(pstrNetworkInfo);
903 pstrNetworkInfo = NULL;
904
905 } else {
906 s32Error = WILC_FAIL;
907 }
908
909 return s32Error;
910 }
911
912 /**
913 * @brief parses the received Association Response frame
914 * @details
915 * @param[in] pu8Buffer The Association Response frame to be parsed
916 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
917 * @return Error code indicating success/failure
918 * @note
919 * @author mabubakr
920 * @date 2 Apr 2012
921 * @version 1.0
922 */
923 s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
924 tstrConnectRespInfo **ppstrConnectRespInfo)
925 {
926 s32 s32Error = WILC_SUCCESS;
927 tstrConnectRespInfo *pstrConnectRespInfo = NULL;
928 u16 u16AssocRespLen = 0;
929 u8 *pu8IEs = 0;
930 u16 u16IEsLen = 0;
931
932 pstrConnectRespInfo = (tstrConnectRespInfo *)WILC_MALLOC(sizeof(tstrConnectRespInfo));
933 WILC_memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
934
935 /* u16AssocRespLen = pu8Buffer[0]; */
936 u16AssocRespLen = (u16)u32BufferLen;
937
938 /* get the status code */
939 pstrConnectRespInfo->u16ConnectStatus = get_asoc_status(pu8Buffer);
940 if (pstrConnectRespInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
941
942 /* get the capability */
943 pstrConnectRespInfo->u16capability = get_assoc_resp_cap_info(pu8Buffer);
944
945 /* get the Association ID */
946 pstrConnectRespInfo->u16AssocID = get_asoc_id(pu8Buffer);
947
948 /* get the Information Elements */
949 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
950 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
951
952 pstrConnectRespInfo->pu8RespIEs = (u8 *)WILC_MALLOC(u16IEsLen);
953 WILC_memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
954
955 WILC_memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
956 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
957 }
958
959 *ppstrConnectRespInfo = pstrConnectRespInfo;
960
961
962 return s32Error;
963 }
964
965 /**
966 * @brief Deallocates the parsed Association Response Info
967 * @details
968 * @param[in] pstrNetworkInfo Network Info to be deallocated
969 * @return Error code indicating success/failure
970 * @note
971 * @author mabubakr
972 * @date 2 Apr 2012
973 * @version 1.0
974 */
975 s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
976 {
977 s32 s32Error = WILC_SUCCESS;
978
979 if (pstrConnectRespInfo != NULL) {
980 if (pstrConnectRespInfo->pu8RespIEs != NULL) {
981 WILC_FREE(pstrConnectRespInfo->pu8RespIEs);
982 pstrConnectRespInfo->pu8RespIEs = NULL;
983 } else {
984 s32Error = WILC_FAIL;
985 }
986
987 WILC_FREE(pstrConnectRespInfo);
988 pstrConnectRespInfo = NULL;
989
990 } else {
991 s32Error = WILC_FAIL;
992 }
993
994 return s32Error;
995 }
996
997 #ifndef CONNECT_DIRECT
998 s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
999 wid_site_survey_reslts_s **ppstrSurveyResults,
1000 u32 *pu32SurveyResultsCount)
1001 {
1002 s32 s32Error = WILC_SUCCESS;
1003 wid_site_survey_reslts_s *pstrSurveyResults = NULL;
1004 u32 u32SurveyResultsCount = 0;
1005 u32 u32SurveyBytesLength = 0;
1006 u8 *pu8BufferPtr;
1007 u32 u32RcvdSurveyResultsNum = 2;
1008 u8 u8ReadSurveyResFragNum;
1009 u32 i;
1010 u32 j;
1011
1012 for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
1013 u32SurveyBytesLength = ppu8RcvdSiteSurveyResults[i][0];
1014
1015
1016 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
1017 u32SurveyResultsCount++;
1018 }
1019 }
1020
1021 pstrSurveyResults = (wid_site_survey_reslts_s *)WILC_MALLOC(u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
1022 if (pstrSurveyResults == NULL) {
1023 u32SurveyResultsCount = 0;
1024 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
1025 }
1026
1027 WILC_memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
1028
1029 u32SurveyResultsCount = 0;
1030
1031 for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
1032 pu8BufferPtr = ppu8RcvdSiteSurveyResults[i];
1033
1034 u32SurveyBytesLength = pu8BufferPtr[0];
1035
1036 /* TODO: mostafa: pu8BufferPtr[1] contains the fragment num */
1037 u8ReadSurveyResFragNum = pu8BufferPtr[1];
1038
1039 pu8BufferPtr += 2;
1040
1041 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
1042 WILC_memcpy(&pstrSurveyResults[u32SurveyResultsCount], pu8BufferPtr, SURVEY_RESULT_LENGTH);
1043 pu8BufferPtr += SURVEY_RESULT_LENGTH;
1044 u32SurveyResultsCount++;
1045 }
1046 }
1047
1048 ERRORHANDLER:
1049 *ppstrSurveyResults = pstrSurveyResults;
1050 *pu32SurveyResultsCount = u32SurveyResultsCount;
1051
1052 return s32Error;
1053 }
1054
1055
1056 s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults)
1057 {
1058 s32 s32Error = WILC_SUCCESS;
1059
1060 if (pstrSurveyResults != NULL) {
1061 WILC_FREE(pstrSurveyResults);
1062 }
1063
1064 return s32Error;
1065 }
1066 #endif
1067
1068 /*****************************************************************************/
1069 /* */
1070 /* Function Name : ProcessCharWid */
1071 /* */
1072 /* Description : This function processes a WID of type WID_CHAR and */
1073 /* updates the cfg packet with the supplied value. */
1074 /* */
1075 /* Inputs : 1) Pointer to WID cfg structure */
1076 /* 2) Value to set */
1077 /* */
1078 /* Globals : */
1079 /* */
1080 /* Processing : */
1081 /* */
1082 /* Outputs : None */
1083 /* */
1084 /* Returns : None */
1085 /* */
1086 /* Issues : None */
1087 /* */
1088 /* Revision History: */
1089 /* */
1090 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1091 /* 08 01 2008 Ittiam Draft */
1092 /* */
1093 /*****************************************************************************/
1094
1095 void ProcessCharWid(char *pcPacket, s32 *ps32PktLen,
1096 tstrWID *pstrWID, s8 *ps8WidVal)
1097 {
1098 u8 *pu8val = (u8 *)ps8WidVal;
1099 u8 u8val = 0;
1100 s32 s32PktLen = *ps32PktLen;
1101 if (pstrWID == NULL) {
1102 PRINT_WRN(CORECONFIG_DBG, "Can't set CHAR val 0x%x ,NULL structure\n", u8val);
1103 return;
1104 }
1105
1106 /* WID */
1107 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1108 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid >> 8) & 0xFF;
1109 if (g_oper_mode == SET_CFG) {
1110 u8val = *pu8val;
1111
1112 /* Length */
1113 pcPacket[s32PktLen++] = sizeof(u8);
1114
1115
1116 /* Value */
1117 pcPacket[s32PktLen++] = u8val;
1118 }
1119 *ps32PktLen = s32PktLen;
1120 }
1121
1122 /*****************************************************************************/
1123 /* */
1124 /* Function Name : ProcessShortWid */
1125 /* */
1126 /* Description : This function processes a WID of type WID_SHORT and */
1127 /* updates the cfg packet with the supplied value. */
1128 /* */
1129 /* Inputs : 1) Pointer to WID cfg structure */
1130 /* 2) Value to set */
1131 /* */
1132 /* Globals : */
1133 /* */
1134 /* Processing : */
1135 /* */
1136 /* Outputs : None */
1137 /* */
1138 /* Returns : None */
1139 /* */
1140 /* Issues : None */
1141 /* */
1142 /* Revision History: */
1143 /* */
1144 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1145 /* 08 01 2008 Ittiam Draft */
1146 /* */
1147 /*****************************************************************************/
1148
1149 void ProcessShortWid(char *pcPacket, s32 *ps32PktLen,
1150 tstrWID *pstrWID, s8 *ps8WidVal)
1151 {
1152 u16 *pu16val = (u16 *)ps8WidVal;
1153 u16 u16val = 0;
1154 s32 s32PktLen = *ps32PktLen;
1155 if (pstrWID == NULL) {
1156 PRINT_WRN(CORECONFIG_DBG, "Can't set SHORT val 0x%x ,NULL structure\n", u16val);
1157 return;
1158 }
1159
1160 /* WID */
1161 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1162 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1163
1164 if (g_oper_mode == SET_CFG) {
1165 u16val = *pu16val;
1166
1167 /* Length */
1168 pcPacket[s32PktLen++] = sizeof(u16);
1169
1170 /* Value */
1171 pcPacket[s32PktLen++] = (u8)(u16val & 0xFF);
1172 pcPacket[s32PktLen++] = (u8)((u16val >> 8) & 0xFF);
1173 }
1174 *ps32PktLen = s32PktLen;
1175 }
1176
1177 /*****************************************************************************/
1178 /* */
1179 /* Function Name : ProcessIntWid */
1180 /* */
1181 /* Description : This function processes a WID of type WID_INT and */
1182 /* updates the cfg packet with the supplied value. */
1183 /* */
1184 /* Inputs : 1) Pointer to WID cfg structure */
1185 /* 2) Value to set */
1186 /* */
1187 /* Globals : */
1188 /* */
1189 /* Processing : */
1190 /* */
1191 /* Outputs : None */
1192 /* */
1193 /* Returns : None */
1194 /* */
1195 /* Issues : None */
1196 /* */
1197 /* Revision History: */
1198 /* */
1199 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1200 /* 08 01 2008 Ittiam Draft */
1201 /* */
1202 /*****************************************************************************/
1203
1204 void ProcessIntWid(char *pcPacket, s32 *ps32PktLen,
1205 tstrWID *pstrWID, s8 *ps8WidVal)
1206 {
1207 u32 *pu32val = (u32 *)ps8WidVal;
1208 u32 u32val = 0;
1209 s32 s32PktLen = *ps32PktLen;
1210 if (pstrWID == NULL) {
1211 PRINT_WRN(CORECONFIG_DBG, "Can't set INT val 0x%x , NULL structure\n", u32val);
1212 return;
1213 }
1214
1215 /* WID */
1216 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1217 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1218
1219 if (g_oper_mode == SET_CFG) {
1220 u32val = *pu32val;
1221
1222 /* Length */
1223 pcPacket[s32PktLen++] = sizeof(u32);
1224
1225 /* Value */
1226 pcPacket[s32PktLen++] = (u8)(u32val & 0xFF);
1227 pcPacket[s32PktLen++] = (u8)((u32val >> 8) & 0xFF);
1228 pcPacket[s32PktLen++] = (u8)((u32val >> 16) & 0xFF);
1229 pcPacket[s32PktLen++] = (u8)((u32val >> 24) & 0xFF);
1230 }
1231 *ps32PktLen = s32PktLen;
1232 }
1233
1234 /*****************************************************************************/
1235 /* */
1236 /* Function Name : ProcessIPwid */
1237 /* */
1238 /* Description : This function processes a WID of type WID_IP and */
1239 /* updates the cfg packet with the supplied value. */
1240 /* */
1241 /* Inputs : 1) Pointer to WID cfg structure */
1242 /* 2) Value to set */
1243 /* */
1244 /* Globals : */
1245 /* */
1246 /* */
1247 /* Processing : */
1248 /* */
1249 /* Outputs : None */
1250 /* */
1251 /* Returns : None */
1252 /* */
1253 /* Issues : None */
1254 /* */
1255 /* Revision History: */
1256 /* */
1257 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1258 /* 08 01 2008 Ittiam Draft */
1259 /* */
1260 /*****************************************************************************/
1261
1262 void ProcessIPwid(char *pcPacket, s32 *ps32PktLen,
1263 tstrWID *pstrWID, u8 *pu8ip)
1264 {
1265 u32 u32val = 0;
1266 s32 s32PktLen = *ps32PktLen;
1267
1268 if (pstrWID == NULL) {
1269 PRINT_WRN(CORECONFIG_DBG, "Can't set IP Addr , NULL structure\n");
1270 return;
1271 }
1272
1273 /* WID */
1274 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1275 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1276
1277 if (g_oper_mode == SET_CFG) {
1278 /* Length */
1279 pcPacket[s32PktLen++] = sizeof(u32);
1280
1281 /* Convert the IP Address String to Integer */
1282 conv_ip_to_int(pu8ip, &u32val);
1283
1284 /* Value */
1285 pcPacket[s32PktLen++] = (u8)(u32val & 0xFF);
1286 pcPacket[s32PktLen++] = (u8)((u32val >> 8) & 0xFF);
1287 pcPacket[s32PktLen++] = (u8)((u32val >> 16) & 0xFF);
1288 pcPacket[s32PktLen++] = (u8)((u32val >> 24) & 0xFF);
1289 }
1290 *ps32PktLen = s32PktLen;
1291 }
1292
1293 /*****************************************************************************/
1294 /* */
1295 /* Function Name : ProcessStrWid */
1296 /* */
1297 /* Description : This function processes a WID of type WID_STR and */
1298 /* updates the cfg packet with the supplied value. */
1299 /* */
1300 /* Inputs : 1) Pointer to WID cfg structure */
1301 /* 2) Value to set */
1302 /* */
1303 /* Globals : */
1304 /* */
1305 /* Processing : */
1306 /* */
1307 /* Outputs : None */
1308 /* */
1309 /* Returns : None */
1310 /* */
1311 /* Issues : None */
1312 /* */
1313 /* Revision History: */
1314 /* */
1315 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1316 /* 08 01 2008 Ittiam Draft */
1317 /* */
1318 /*****************************************************************************/
1319
1320 void ProcessStrWid(char *pcPacket, s32 *ps32PktLen,
1321 tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize)
1322 {
1323 u16 u16MsgLen = 0;
1324 u16 idx = 0;
1325 s32 s32PktLen = *ps32PktLen;
1326 if (pstrWID == NULL) {
1327 PRINT_WRN(CORECONFIG_DBG, "Can't set STR val, NULL structure\n");
1328 return;
1329 }
1330
1331 /* WID */
1332 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1333 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1334
1335 if (g_oper_mode == SET_CFG) {
1336 /* Message Length */
1337 /* u16MsgLen = WILC_strlen(pu8val); */
1338 u16MsgLen = (u16)s32ValueSize;
1339
1340 /* Length */
1341 pcPacket[s32PktLen++] = (u8)u16MsgLen;
1342
1343 /* Value */
1344 for (idx = 0; idx < u16MsgLen; idx++)
1345 pcPacket[s32PktLen++] = pu8val[idx];
1346 }
1347 *ps32PktLen = s32PktLen;
1348 }
1349
1350 /*****************************************************************************/
1351 /* */
1352 /* Function Name : ProcessAdrWid */
1353 /* */
1354 /* Description : This function processes a WID of type WID_ADR and */
1355 /* updates the cfg packet with the supplied value. */
1356 /* */
1357 /* Inputs : 1) Pointer to WID cfg structure */
1358 /* 2) Value to set */
1359 /* */
1360 /* Globals : */
1361 /* */
1362 /* Processing : */
1363 /* */
1364 /* Outputs : None */
1365 /* */
1366 /* Returns : None */
1367 /* */
1368 /* Issues : None */
1369 /* */
1370 /* Revision History: */
1371 /* */
1372 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1373 /* 08 01 2008 Ittiam Draft */
1374 /* */
1375 /*****************************************************************************/
1376
1377 void ProcessAdrWid(char *pcPacket, s32 *ps32PktLen,
1378 tstrWID *pstrWID, u8 *pu8val)
1379 {
1380 u16 u16MsgLen = 0;
1381 s32 s32PktLen = *ps32PktLen;
1382
1383 if (pstrWID == NULL) {
1384 PRINT_WRN(CORECONFIG_DBG, "Can't set Addr WID, NULL structure\n");
1385 return;
1386 }
1387
1388 /* WID */
1389 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1390 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1391
1392 if (g_oper_mode == SET_CFG) {
1393 /* Message Length */
1394 u16MsgLen = MAC_ADDR_LEN;
1395
1396 /* Length */
1397 pcPacket[s32PktLen++] = (u8)u16MsgLen;
1398
1399 /* Value */
1400 extract_mac_addr(pu8val, pcPacket + s32PktLen);
1401 s32PktLen += u16MsgLen;
1402 }
1403 *ps32PktLen = s32PktLen;
1404 }
1405
1406 /*****************************************************************************/
1407 /* */
1408 /* Function Name : ProcessBinWid */
1409 /* */
1410 /* Description : This function processes a WID of type WID_BIN_DATA and */
1411 /* updates the cfg packet with the supplied value. */
1412 /* */
1413 /* Inputs : 1) Pointer to WID cfg structure */
1414 /* 2) Name of file containing the binary data in text mode */
1415 /* */
1416 /* Globals : */
1417 /* */
1418 /* Processing : The binary data is expected to be supplied through a */
1419 /* file in text mode. This file is expected to be in the */
1420 /* finject format. It is parsed, converted to binary format */
1421 /* and copied into g_cfg_pkt for further processing. This */
1422 /* is obviously a round-about way of processing involving */
1423 /* multiple (re)conversions between bin & ascii formats. */
1424 /* But it is done nevertheless to retain uniformity and for */
1425 /* ease of debugging. */
1426 /* */
1427 /* Outputs : None */
1428 /* */
1429 /* Returns : None */
1430 /* */
1431
1432 /* Issues : None */
1433 /* */
1434 /* Revision History: */
1435 /* */
1436 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1437 /* 08 01 2008 Ittiam Draft */
1438 /* */
1439 /*****************************************************************************/
1440
1441 void ProcessBinWid(char *pcPacket, s32 *ps32PktLen,
1442 tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize)
1443 {
1444 /* WILC_ERROR("processing Binary WIDs is not supported\n"); */
1445
1446 u16 u16MsgLen = 0;
1447 u16 idx = 0;
1448 s32 s32PktLen = *ps32PktLen;
1449 u8 u8checksum = 0;
1450
1451 if (pstrWID == NULL) {
1452 PRINT_WRN(CORECONFIG_DBG, "Can't set BIN val, NULL structure\n");
1453 return;
1454 }
1455
1456 /* WID */
1457 pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
1458 pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
1459
1460 if (g_oper_mode == SET_CFG) {
1461 /* Message Length */
1462 u16MsgLen = (u16)s32ValueSize;
1463
1464 /* Length */
1465 /* pcPacket[s32PktLen++] = (u8)u16MsgLen; */
1466 pcPacket[s32PktLen++] = (u8)(u16MsgLen & 0xFF);
1467 pcPacket[s32PktLen++] = (u8)((u16MsgLen >> 8) & 0xFF);
1468
1469 /* Value */
1470 for (idx = 0; idx < u16MsgLen; idx++)
1471 pcPacket[s32PktLen++] = pu8val[idx];
1472
1473 /* checksum */
1474 for (idx = 0; idx < u16MsgLen; idx++)
1475 u8checksum += pcPacket[MSG_HEADER_LEN + idx + 4];
1476
1477 pcPacket[s32PktLen++] = u8checksum;
1478 }
1479 *ps32PktLen = s32PktLen;
1480 }
1481
1482
1483 /*****************************************************************************/
1484 /* */
1485 /* Function Name : further_process_response */
1486 /* */
1487 /* Description : This function parses the response frame got from the */
1488 /* device. */
1489 /* */
1490 /* Inputs : 1) The received response frame */
1491 /* 2) WID */
1492 /* 3) WID Length */
1493 /* 4) Output file handle */
1494 /* 5) Process Wid Number(i.e wid from --widn switch) */
1495 /* 6) Index the array in the Global Wid Structure. */
1496 /* */
1497 /* Globals : g_wid_num, gastrWIDs */
1498 /* */
1499 /* Processing : This function parses the response of the device depending*/
1500 /* WID type and writes it to the output file in Hex or */
1501 /* decimal notation depending on the --getx or --get switch.*/
1502 /* */
1503 /* Outputs : None */
1504 /* */
1505 /* Returns : 0 on Success & -2 on Failure */
1506 /* */
1507 /* Issues : None */
1508 /* */
1509 /* Revision History: */
1510 /* */
1511 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1512 /* 08 01 2009 Ittiam Draft */
1513 /* */
1514 /*****************************************************************************/
1515
1516 s32 further_process_response(u8 *resp,
1517 u16 u16WIDid,
1518 u16 cfg_len,
1519 bool process_wid_num,
1520 u32 cnt,
1521 tstrWID *pstrWIDresult)
1522 {
1523 u32 retval = 0;
1524 u32 idx = 0;
1525 u8 cfg_chr = 0;
1526 u16 cfg_sht = 0;
1527 u32 cfg_int = 0;
1528 u8 cfg_str[256] = {0};
1529 tenuWIDtype enuWIDtype = WID_UNDEF;
1530
1531 if (process_wid_num) {
1532 enuWIDtype = get_wid_type(g_wid_num);
1533 } else {
1534 enuWIDtype = gastrWIDs[cnt].enuWIDtype;
1535 }
1536
1537
1538 switch (enuWIDtype) {
1539 case WID_CHAR:
1540 cfg_chr = resp[idx];
1541 /*Set local copy of WID*/
1542 *(pstrWIDresult->ps8WidVal) = cfg_chr;
1543 break;
1544
1545 case WID_SHORT:
1546 {
1547 u16 *pu16val = (u16 *)(pstrWIDresult->ps8WidVal);
1548 cfg_sht = MAKE_WORD16(resp[idx], resp[idx + 1]);
1549 /*Set local copy of WID*/
1550 /* pstrWIDresult->ps8WidVal = (s8*)(s32)cfg_sht; */
1551 *pu16val = cfg_sht;
1552 break;
1553 }
1554
1555 case WID_INT:
1556 {
1557 u32 *pu32val = (u32 *)(pstrWIDresult->ps8WidVal);
1558 cfg_int = MAKE_WORD32(
1559 MAKE_WORD16(resp[idx], resp[idx + 1]),
1560 MAKE_WORD16(resp[idx + 2], resp[idx + 3])
1561 );
1562 /*Set local copy of WID*/
1563 /* pstrWIDresult->ps8WidVal = (s8*)cfg_int; */
1564 *pu32val = cfg_int;
1565 break;
1566 }
1567
1568 case WID_STR:
1569 WILC_memcpy(cfg_str, resp + idx, cfg_len);
1570 /* cfg_str[cfg_len] = '\0'; //mostafa: no need currently for NULL termination */
1571 if (process_wid_num) {
1572 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1573 * cfg_str);*/
1574 } else {
1575 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1576 * cfg_str);*/
1577 }
1578
1579 if (pstrWIDresult->s32ValueSize >= cfg_len) {
1580 WILC_memcpy(pstrWIDresult->ps8WidVal, cfg_str, cfg_len); /* mostafa: no need currently for the extra NULL byte */
1581 pstrWIDresult->s32ValueSize = cfg_len;
1582 } else {
1583 PRINT_ER("allocated WID buffer length is smaller than the received WID Length\n");
1584 retval = -2;
1585 }
1586
1587 break;
1588
1589 case WID_ADR:
1590 create_mac_addr(cfg_str, resp + idx);
1591
1592 WILC_strncpy(pstrWIDresult->ps8WidVal, cfg_str, WILC_strlen(cfg_str));
1593 pstrWIDresult->ps8WidVal[WILC_strlen(cfg_str)] = '\0';
1594 if (process_wid_num) {
1595 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1596 * cfg_str);*/
1597 } else {
1598 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1599 * cfg_str);*/
1600 }
1601 break;
1602
1603 case WID_IP:
1604 cfg_int = MAKE_WORD32(
1605 MAKE_WORD16(resp[idx], resp[idx + 1]),
1606 MAKE_WORD16(resp[idx + 2], resp[idx + 3])
1607 );
1608 conv_int_to_ip(cfg_str, cfg_int);
1609 if (process_wid_num) {
1610 /*fprintf(out_file,"0x%4.4x = %s\n",g_wid_num,
1611 * cfg_str);*/
1612 } else {
1613 /*fprintf(out_file,"%s = %s\n",gastrWIDs[cnt].cfg_switch,
1614 * cfg_str);*/
1615 }
1616 break;
1617
1618 case WID_BIN_DATA:
1619 if (pstrWIDresult->s32ValueSize >= cfg_len) {
1620 WILC_memcpy(pstrWIDresult->ps8WidVal, resp + idx, cfg_len);
1621 pstrWIDresult->s32ValueSize = cfg_len;
1622 } else {
1623 PRINT_ER("Allocated WID buffer length is smaller than the received WID Length Err(%d)\n", retval);
1624 retval = -2;
1625 }
1626 break;
1627
1628 default:
1629 PRINT_ER("ERROR: Check config database: Error(%d)\n", retval);
1630 retval = -2;
1631 break;
1632 }
1633
1634 return retval;
1635 }
1636
1637 /*****************************************************************************/
1638 /* */
1639 /* Function Name : ParseResponse */
1640 /* */
1641 /* Description : This function parses the command-line options and */
1642 /* creates the config packets which can be sent to the WLAN */
1643 /* station. */
1644 /* */
1645 /* Inputs : 1) The received response frame */
1646 /* */
1647 /* Globals : g_opt_list, gastrWIDs */
1648 /* */
1649 /* Processing : This function parses the options and creates different */
1650 /* types of packets depending upon the WID-type */
1651 /* corresponding to the option. */
1652 /* */
1653 /* Outputs : None */
1654 /* */
1655 /* Returns : 0 on Success & -1 on Failure */
1656 /* */
1657 /* Issues : None */
1658 /* */
1659 /* Revision History: */
1660 /* */
1661 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1662 /* 08 01 2008 Ittiam Draft */
1663 /* */
1664 /*****************************************************************************/
1665
1666 s32 ParseResponse(u8 *resp, tstrWID *pstrWIDcfgResult)
1667 {
1668 u16 u16RespLen = 0;
1669 u16 u16WIDid = 0;
1670 u16 cfg_len = 0;
1671 tenuWIDtype enuWIDtype = WID_UNDEF;
1672 bool num_wid_processed = false;
1673 u32 cnt = 0;
1674 u32 idx = 0;
1675 u32 ResCnt = 0;
1676 /* Check whether the received frame is a valid response */
1677 if (RESP_MSG_TYPE != resp[0]) {
1678 PRINT_INFO(CORECONFIG_DBG, "Received Message format incorrect.\n");
1679 return -1;
1680 }
1681
1682 /* Extract Response Length */
1683 u16RespLen = MAKE_WORD16(resp[2], resp[3]);
1684 Res_Len = u16RespLen;
1685
1686 for (idx = MSG_HEADER_LEN; idx < u16RespLen; ) {
1687 u16WIDid = MAKE_WORD16(resp[idx], resp[idx + 1]);
1688 cfg_len = resp[idx + 2];
1689 /* Incase of Bin Type Wid, the length is given by two byte field */
1690 enuWIDtype = get_wid_type(u16WIDid);
1691 if (WID_BIN_DATA == enuWIDtype) {
1692 cfg_len |= ((u16)resp[idx + 3] << 8) & 0xFF00;
1693 idx++;
1694 }
1695 idx += 3;
1696 if ((u16WIDid == g_wid_num) && (!num_wid_processed)) {
1697 num_wid_processed = true;
1698
1699 if (-2 == further_process_response(&resp[idx], u16WIDid, cfg_len, true, 0, &pstrWIDcfgResult[ResCnt])) {
1700 return -2;
1701 }
1702 ResCnt++;
1703 } else {
1704 for (cnt = 0; cnt < g_num_total_switches; cnt++) {
1705 if (gastrWIDs[cnt].u16WIDid == u16WIDid) {
1706 if (-2 == further_process_response(&resp[idx], u16WIDid, cfg_len, false, cnt,
1707 &pstrWIDcfgResult[ResCnt])) {
1708 return -2;
1709 }
1710 ResCnt++;
1711 }
1712 }
1713 }
1714 idx += cfg_len;
1715 /* In case if BIN type Wid, The last byte of the Cfg packet is the */
1716 /* Checksum. The WID Length field does not accounts for the checksum. */
1717 /* The Checksum is discarded. */
1718 if (WID_BIN_DATA == enuWIDtype) {
1719 idx++;
1720 }
1721 }
1722
1723 return 0;
1724 }
1725
1726 /**
1727 * @brief parses the write response [just detects its status: success or failure]
1728 * @details
1729 * @param[in] pu8RespBuffer The Response to be parsed
1730 * @return Error code indicating Write Operation status:
1731 * WRITE_RESP_SUCCESS (1) => Write Success.
1732 * WILC_FAIL (-100) => Write Failure.
1733 * @note
1734 * @author Ittiam
1735 * @date 11 Aug 2009
1736 * @version 1.0
1737 */
1738
1739 s32 ParseWriteResponse(u8 *pu8RespBuffer)
1740 {
1741 s32 s32Error = WILC_FAIL;
1742 u16 u16RespLen = 0;
1743 u16 u16WIDtype = (u16)WID_NIL;
1744
1745 /* Check whether the received frame is a valid response */
1746 if (RESP_MSG_TYPE != pu8RespBuffer[0]) {
1747 PRINT_ER("Received Message format incorrect.\n");
1748 return WILC_FAIL;
1749 }
1750
1751 /* Extract Response Length */
1752 u16RespLen = MAKE_WORD16(pu8RespBuffer[2], pu8RespBuffer[3]);
1753
1754 u16WIDtype = MAKE_WORD16(pu8RespBuffer[4], pu8RespBuffer[5]);
1755
1756 /* Check for WID_STATUS ID and then check the length and status value */
1757 if ((u16WIDtype == WID_STATUS) &&
1758 (pu8RespBuffer[6] == 1) &&
1759 (pu8RespBuffer[7] == WRITE_RESP_SUCCESS)) {
1760 s32Error = WRITE_RESP_SUCCESS;
1761 return s32Error;
1762 }
1763
1764 /* If the length or status are not as expected return failure */
1765 s32Error = WILC_FAIL;
1766 return s32Error;
1767
1768 }
1769
1770 /**
1771 * @brief creates the header of the Configuration Packet
1772 * @details
1773 * @param[in,out] pcpacket The Configuration Packet
1774 * @param[in,out] ps32PacketLength Length of the Configuration Packet
1775 * @return Error code indicating success/failure
1776 * @note
1777 * @author aismail
1778 * @date 18 Feb 2012
1779 * @version 1.0
1780 */
1781
1782 s32 CreatePacketHeader(char *pcpacket, s32 *ps32PacketLength)
1783 {
1784 s32 s32Error = WILC_SUCCESS;
1785 u16 u16MsgLen = (u16)(*ps32PacketLength);
1786 u16 u16MsgInd = 0;
1787
1788 /* The format of the message is: */
1789 /* +-------------------------------------------------------------------+ */
1790 /* | Message Type | Message ID | Message Length |Message body | */
1791 /* +-------------------------------------------------------------------+ */
1792 /* | 1 Byte | 1 Byte | 2 Bytes | Message Length - 4 | */
1793 /* +-------------------------------------------------------------------+ */
1794
1795 /* The format of a message body of a message type 'W' is: */
1796 /* +-------------------------------------------------------------------+ */
1797 /* | WID0 | WID0 Length | WID0 Value | ......................... | */
1798 /* +-------------------------------------------------------------------+ */
1799 /* | 2 Bytes | 1 Byte | WID0 Length | ......................... | */
1800 /* +-------------------------------------------------------------------+ */
1801
1802
1803
1804 /* Message Type */
1805 if (g_oper_mode == SET_CFG)
1806 pcpacket[u16MsgInd++] = WRITE_MSG_TYPE;
1807 else
1808 pcpacket[u16MsgInd++] = QUERY_MSG_TYPE;
1809
1810 /* Sequence Number */
1811 pcpacket[u16MsgInd++] = g_seqno++;
1812
1813 /* Message Length */
1814 pcpacket[u16MsgInd++] = (u8)(u16MsgLen & 0xFF);
1815 pcpacket[u16MsgInd++] = (u8)((u16MsgLen >> 8) & 0xFF);
1816
1817 *ps32PacketLength = u16MsgLen;
1818
1819 return s32Error;
1820 }
1821
1822 /**
1823 * @brief creates Configuration packet based on the Input WIDs
1824 * @details
1825 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
1826 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
1827 * @param[out] ps8packet The created Configuration Packet
1828 * @param[out] ps32PacketLength Length of the created Configuration Packet
1829 * @return Error code indicating success/failure
1830 * @note
1831 * @author
1832 * @date 1 Mar 2012
1833 * @version 1.0
1834 */
1835
1836 s32 CreateConfigPacket(s8 *ps8packet, s32 *ps32PacketLength,
1837 tstrWID *pstrWIDs, u32 u32WIDsCount)
1838 {
1839 s32 s32Error = WILC_SUCCESS;
1840 u32 u32idx = 0;
1841 *ps32PacketLength = MSG_HEADER_LEN;
1842 for (u32idx = 0; u32idx < u32WIDsCount; u32idx++) {
1843 switch (pstrWIDs[u32idx].enuWIDtype) {
1844 case WID_CHAR:
1845 ProcessCharWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1846 pstrWIDs[u32idx].ps8WidVal);
1847 break;
1848
1849 case WID_SHORT:
1850 ProcessShortWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1851 pstrWIDs[u32idx].ps8WidVal);
1852 break;
1853
1854 case WID_INT:
1855 ProcessIntWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1856 pstrWIDs[u32idx].ps8WidVal);
1857 break;
1858
1859 case WID_STR:
1860 ProcessStrWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1861 pstrWIDs[u32idx].ps8WidVal, pstrWIDs[u32idx].s32ValueSize);
1862 break;
1863
1864 case WID_IP:
1865 ProcessIPwid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1866 pstrWIDs[u32idx].ps8WidVal);
1867 break;
1868
1869 case WID_BIN_DATA:
1870 ProcessBinWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
1871 pstrWIDs[u32idx].ps8WidVal, pstrWIDs[u32idx].s32ValueSize);
1872 break;
1873
1874 default:
1875 PRINT_ER("ERROR: Check Config database\n");
1876 }
1877 }
1878
1879 CreatePacketHeader(ps8packet, ps32PacketLength);
1880
1881 return s32Error;
1882 }
1883
1884 s32 ConfigWaitResponse(char *pcRespBuffer, s32 s32MaxRespBuffLen, s32 *ps32BytesRead,
1885 bool bRespRequired)
1886 {
1887 s32 s32Error = WILC_SUCCESS;
1888 /*bug 3878*/
1889 /*removed to caller function*/
1890 /*gstrConfigPktInfo.pcRespBuffer = pcRespBuffer;
1891 * gstrConfigPktInfo.s32MaxRespBuffLen = s32MaxRespBuffLen;
1892 * gstrConfigPktInfo.bRespRequired = bRespRequired;*/
1893
1894
1895 if (gstrConfigPktInfo.bRespRequired) {
1896 down(&SemHandlePktResp);
1897
1898 *ps32BytesRead = gstrConfigPktInfo.s32BytesRead;
1899 }
1900
1901 WILC_memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
1902
1903 return s32Error;
1904 }
1905
1906 /**
1907 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
1908 * and retrieves the packet response pu8RxResp
1909 * @details
1910 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
1911 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
1912 * @param[out] pu8RxResp The received Packet Response
1913 * @param[out] ps32RxRespLen Length of the received Packet Response
1914 * @return Error code indicating success/failure
1915 * @note
1916 * @author mabubakr
1917 * @date 1 Mar 2012
1918 * @version 1.0
1919 */
1920 #ifdef SIMULATION
1921 s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
1922 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler)
1923 {
1924 s32 s32Error = WILC_SUCCESS;
1925 s32 err = WILC_SUCCESS;
1926 s32 s32ConfigPacketLen = 0;
1927 s32 s32RcvdRespLen = 0;
1928
1929 down(&SemHandleSendPkt);
1930
1931 /*set the packet mode*/
1932 g_oper_mode = u8Mode;
1933
1934 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
1935
1936 if (CreateConfigPacket(gps8ConfigPacket, &s32ConfigPacketLen, pstrWIDs, u32WIDsCount) != WILC_SUCCESS) {
1937 s32Error = WILC_FAIL;
1938 goto End_ConfigPkt;
1939 }
1940 /*bug 3878*/
1941 gstrConfigPktInfo.pcRespBuffer = gps8ConfigPacket;
1942 gstrConfigPktInfo.s32MaxRespBuffLen = MAX_PACKET_BUFF_SIZE;
1943 PRINT_INFO(CORECONFIG_DBG, "GLOBAL =bRespRequired =%d\n", bRespRequired);
1944 gstrConfigPktInfo.bRespRequired = bRespRequired;
1945
1946 s32Error = SendRawPacket(gps8ConfigPacket, s32ConfigPacketLen);
1947 if (s32Error != WILC_SUCCESS) {
1948 goto End_ConfigPkt;
1949 }
1950
1951 WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
1952
1953 ConfigWaitResponse(gps8ConfigPacket, MAX_PACKET_BUFF_SIZE, &s32RcvdRespLen, bRespRequired);
1954
1955
1956 if (bRespRequired) {
1957 /* If the operating Mode is GET, then we expect a response frame from */
1958 /* the driver. Hence start listening to the port for response */
1959 if (g_oper_mode == GET_CFG) {
1960 #if 1
1961 err = ParseResponse(gps8ConfigPacket, pstrWIDs);
1962 if (err != 0) {
1963 s32Error = WILC_FAIL;
1964 goto End_ConfigPkt;
1965 } else {
1966 s32Error = WILC_SUCCESS;
1967 }
1968 #endif
1969 } else {
1970 err = ParseWriteResponse(gps8ConfigPacket);
1971 if (err != WRITE_RESP_SUCCESS) {
1972 s32Error = WILC_FAIL;
1973 goto End_ConfigPkt;
1974 } else {
1975 s32Error = WILC_SUCCESS;
1976 }
1977 }
1978
1979
1980 }
1981
1982
1983 End_ConfigPkt:
1984 up(&SemHandleSendPkt);
1985
1986 return s32Error;
1987 }
1988 #endif
1989 s32 ConfigProvideResponse(char *pcRespBuffer, s32 s32RespLen)
1990 {
1991 s32 s32Error = WILC_SUCCESS;
1992
1993 if (gstrConfigPktInfo.bRespRequired) {
1994 if (s32RespLen <= gstrConfigPktInfo.s32MaxRespBuffLen) {
1995 WILC_memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, s32RespLen);
1996 gstrConfigPktInfo.s32BytesRead = s32RespLen;
1997 } else {
1998 WILC_memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, gstrConfigPktInfo.s32MaxRespBuffLen);
1999 gstrConfigPktInfo.s32BytesRead = gstrConfigPktInfo.s32MaxRespBuffLen;
2000 PRINT_ER("BusProvideResponse() Response greater than the prepared Buffer Size\n");
2001 }
2002
2003 up(&SemHandlePktResp);
2004 }
2005
2006 return s32Error;
2007 }
2008
2009 /**
2010 * @brief writes the received packet pu8RxPacket in the global Rx FIFO buffer
2011 * @details
2012 * @param[in] pu8RxPacket The received packet
2013 * @param[in] s32RxPacketLen Length of the received packet
2014 * @return Error code indicating success/failure
2015 * @note
2016 *
2017 * @author mabubakr
2018 * @date 1 Mar 2012
2019 * @version 1.0
2020 */
2021
2022 s32 ConfigPktReceived(u8 *pu8RxPacket, s32 s32RxPacketLen)
2023 {
2024 s32 s32Error = WILC_SUCCESS;
2025 u8 u8MsgType = 0;
2026
2027 u8MsgType = pu8RxPacket[0];
2028
2029 switch (u8MsgType) {
2030 case 'R':
2031 ConfigProvideResponse(pu8RxPacket, s32RxPacketLen);
2032
2033 break;
2034
2035 case 'N':
2036 PRINT_INFO(CORECONFIG_DBG, "NetworkInfo packet received\n");
2037 NetworkInfoReceived(pu8RxPacket, s32RxPacketLen);
2038 break;
2039
2040 case 'I':
2041 GnrlAsyncInfoReceived(pu8RxPacket, s32RxPacketLen);
2042 break;
2043
2044 case 'S':
2045 host_int_ScanCompleteReceived(pu8RxPacket, s32RxPacketLen);
2046 break;
2047
2048 default:
2049 PRINT_ER("ConfigPktReceived(): invalid received msg type at the Core Configurator\n");
2050 break;
2051 }
2052
2053 return s32Error;
2054 }
2055
2056 /**
2057 * @brief Deinitializes the Core Configurator
2058 * @details
2059 * @return Error code indicating success/failure
2060 * @note
2061 * @author mabubakr
2062 * @date 1 Mar 2012
2063 * @version 1.0
2064 */
2065
2066 s32 CoreConfiguratorDeInit(void)
2067 {
2068 s32 s32Error = WILC_SUCCESS;
2069
2070 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorDeInit()\n");
2071
2072 if (gps8ConfigPacket != NULL) {
2073
2074 WILC_FREE(gps8ConfigPacket);
2075 gps8ConfigPacket = NULL;
2076 }
2077
2078 return s32Error;
2079 }
2080
2081
2082 #ifndef SIMULATION
2083 /*Using the global handle of the driver*/
2084 extern wilc_wlan_oup_t *gpstrWlanOps;
2085 /**
2086 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
2087 * using driver config layer
2088 *
2089 * @details
2090 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
2091 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
2092 * @param[out] pu8RxResp The received Packet Response
2093 * @param[out] ps32RxRespLen Length of the received Packet Response
2094 * @return Error code indicating success/failure
2095 * @note
2096 * @author mabubakr
2097 * @date 1 Mar 2012
2098 * @version 1.0
2099 */
2100 s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
2101 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler)
2102 {
2103 s32 counter = 0, ret = 0;
2104 if (gpstrWlanOps == NULL) {
2105 PRINT_D(CORECONFIG_DBG, "Net Dev is still not initialized\n");
2106 return 1;
2107 } else {
2108 PRINT_D(CORECONFIG_DBG, "Net Dev is initialized\n");
2109 }
2110 if (gpstrWlanOps->wlan_cfg_set == NULL ||
2111 gpstrWlanOps->wlan_cfg_get == NULL) {
2112 PRINT_D(CORECONFIG_DBG, "Set and Get is still not initialized\n");
2113 return 1;
2114 } else {
2115 PRINT_D(CORECONFIG_DBG, "SET is initialized\n");
2116 }
2117 if (u8Mode == GET_CFG) {
2118 for (counter = 0; counter < u32WIDsCount; counter++) {
2119 PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
2120 (counter == u32WIDsCount - 1));
2121 if (!gpstrWlanOps->wlan_cfg_get(!counter,
2122 pstrWIDs[counter].u16WIDid,
2123 (counter == u32WIDsCount - 1), drvHandler)) {
2124 ret = -1;
2125 printk("[Sendconfigpkt]Get Timed out\n");
2126 break;
2127 }
2128 }
2129 /**
2130 * get the value
2131 **/
2132 /* WILC_Sleep(1000); */
2133 counter = 0;
2134 for (counter = 0; counter < u32WIDsCount; counter++) {
2135 pstrWIDs[counter].s32ValueSize = gpstrWlanOps->wlan_cfg_get_value(
2136 pstrWIDs[counter].u16WIDid,
2137 pstrWIDs[counter].ps8WidVal, pstrWIDs[counter].s32ValueSize);
2138
2139 }
2140 } else if (u8Mode == SET_CFG) {
2141 for (counter = 0; counter < u32WIDsCount; counter++) {
2142 PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", pstrWIDs[counter].u16WIDid);
2143 if (!gpstrWlanOps->wlan_cfg_set(!counter,
2144 pstrWIDs[counter].u16WIDid, pstrWIDs[counter].ps8WidVal,
2145 pstrWIDs[counter].s32ValueSize,
2146 (counter == u32WIDsCount - 1), drvHandler)) {
2147 ret = -1;
2148 printk("[Sendconfigpkt]Set Timed out\n");
2149 break;
2150 }
2151 }
2152 }
2153
2154 return ret;
2155 }
2156 #endif
This page took 0.074023 seconds and 6 git commands to generate.