Mistake on this page?
Report an issue in GitHub or email us
rda5991h_wland.h
1 /* Copyright (c) 2019 Unisoc Communications Inc.
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _RDA5991H_WLAND_H_
18 #define _RDA5991H_WLAND_H_
19 
20 #include "sys_arch.h"
21 #include "wland_types.h"
22 
23 /* Mbed interface mac address
24  * if MBED_MAC_ADD_x are zero, interface uid sets mac address,
25  * otherwise MAC_ADD_x are used.
26  */
27 
28 extern unsigned char user_mac[6];//not save in flash, need fill before wifi init every time
29 extern unsigned char gssid[32+1];
30 extern unsigned char gpass[64+1];
31 extern unsigned char gchannel;
32 extern unsigned char gbssid[6];
33 
34 extern unsigned char gssid_ap[32+1];
35 extern unsigned char gpass_ap[64+1];
36 extern unsigned char gchannel_ap;
37 extern void *wland_msgQ;
38 extern void *wifi_auth_sem;
39 
40 extern u8 sta_state;
41 
42 typedef enum {
43  WLAND_CONNECT,
44  WLAND_RECONNECT,
45  WLAND_DISCONNECT,
46  WLAND_DISCONNECT_ERROR,
47  WLAND_STARTAP,
48  WLAND_STOPAP,
49  WLAND_ADD_AP_GTK,
50  WLAND_AP_EAPOL_3_OF_4,
51  WLAND_ADD_AP_PTK,
52  WLAND_STAJOINED,
53  WLAND_STAEXITED,
54  WLAND_STADEAUTH,
55  WLAND_STADELETETIMER,
56  WLAND_MAC_CONNECTED,
57  WLAND_MAC_AP_CONNECTED,
58  WLAND_ADD_GTK,
59  WLAND_ADD_PTK,
60  WLAND_CON_FINISH,
61  WLAND_AUTO_RATE,
62  WLAND_ARP_OFFLOAD,
63  WLAND_SM_START,
64  WLAND_SM_STOP,
65  WLAND_WPS_CONNECT,
66  WLAND_WPS_START,
67  WLAND_WPS_DISCONNECT,
68 }WLAND_MSG;
69 
70 typedef enum {
71  MAIN_CONNECT,
72  MAIN_RECONNECT,
73  MAIN_DISCONNECT,
74  MAIN_STOP_AP,
75 }MAIN_MSG;
76 
77 typedef struct {
78  unsigned int type;
79  unsigned int arg1;
80  unsigned int arg2;
81  unsigned int arg3;
82 }rda_msg;
83 
84 
85 enum {
86  D_NONE_LEVEL = 0,
87  D_ERROR_LEVEL = 1,
88  D_INFO_LEVEL = 2,
89  D_DEBUG_LEVEL = 3,
90 };
91 
92 #define WLAND_DBG_DUMP 0
93 #define WPA_DBG_DUMP 0
94 #define HUT_DBG_DUMP 0
95 #define WLAND_DBG_LEVEL D_NONE_LEVEL
96 #define WPA_DBG_LEBEL D_NONE_LEVEL
97 #define WLANDLIB_DBG_LEVEL D_NONE_LEVEL
98 
99 #define ETH_ALEN 6
100 
101 //encrypt type
102 #define ENCRYPT_NONE (0)
103 #define ENCRYPT_WPA_TKIP BIT0
104 #define ENCRYPT_WPA_CCMP BIT1
105 #define ENCRYPT_WPA2_TKIP BIT2
106 #define ENCRYPT_WPA2_CCMP BIT3
107 #define ENCRYPT_WEP BIT4
108 
109 /* r91h driver data structure */
110 typedef struct {
111  struct netif *netif_sta;
112  struct netif *netif_ap;
113  sys_thread_t wland_thread;
114  sys_thread_t maclib_thread;
115  sys_mbox_t maclib_mbox;
116  sys_mbox_t wland_mbox;
118 
119 __STATIC_INLINE int mac_is_valid(char* mac)
120 {
121  return (mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]);
122 }
123 
124 
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128 
129 extern void wland_txip_data(void *data, unsigned int len, int mode);
130 extern void *wland_get_databuf(void);
131 extern void wland_sta_init(void);
132 extern void wland_reg_func(void);
133 extern void r91h_phy_task(void *data);
134 extern void wland_task(void *arg);
135 extern void rda_get_macaddr(u8_t *macaddr, int mode);
136 extern void rda5981_send_rawdata(char* data, unsigned int len);
137 extern int rda5981_send_nulldata(int power_save);
138 extern void rda5981_set_country_code(unsigned char country_code);// 0~china(1-14) 1~NA(1-11) 2~EU(1-13)
139 extern int rda5981_set_retrans_policy(unsigned char count);
140 extern int rda5981_set_channel(unsigned char channel);
141 /* default is 0, receive multicast packet, disable please set 1*/
142 extern int rda5981_filter_multicast(unsigned char enable);
143 /* default is 0, 0 ~ no hidden, 1 ~ hidden zero len, 2 ~ hidden zero contents */
144 extern void rda5981_set_AP_hidden_type(unsigned char mode);
145 extern void rda5981_set_AP_link_num(unsigned char num);
146 extern char* rda5981_get_ver(void);
147 extern int rda5981_enter_CE_MODE(unsigned char enable);
148 /*
149  * mode 0 - not 11n 1 - 11n
150  *
151  * -----------------11n(mode 1)(Mbps)-----------------
152  * rate HT20 HT40
153  * GI(800ns) GI(400ns) GI(800ns) GI(400ns)
154  * 0 6.5 7.2 13.5 15
155  * 1 13 14.2 27 30
156  * 2 19.5 21.7 40.5 45
157  * 3 26 28.9 54 60
158  * 4 39 43.3 81 90
159  * 5 52 57.8 108 120
160  * 6 58.5 65 121.5 135
161  * 7 65 72 135 150
162  *
163  * --------------not 11n(mode 0)(Mbps)-----------------
164  * rate data rate rate data rate
165  * 0 autorate 9 9
166  * 1 1 12 12
167  * 2 2 18 18
168  * 5 5.5 24 24
169  * 11 11 36 36
170  * 6 6 48 48
171  *
172  */
173 extern int rda5981_set_data_rate(unsigned char mode, unsigned char rate);
174 extern void rda5981_set_mode(unsigned char bgn_enable);
175 extern void rda5981_set_auth_timeout(unsigned char timeout_enable);
176 typedef struct {
177  char BSSID[ETH_ALEN];
178  char SSID[32+1];
179  signed char RSSI;
180  unsigned char SSID_len;
181  unsigned char channel;
182  unsigned char secure_type;//refer #define ENCRYPT_XXX
183  unsigned char wmm;
184  unsigned char *ie;//user program couldn't free(ie);
185  unsigned short capability;
186  unsigned int ie_length;
188 
189 typedef struct {
190  unsigned char mac[ETH_ALEN];
191  unsigned int ip;
193 
194 //scan one or all channel(if channel is 0) once
195 int rda5981_scan(const char *SSID, const unsigned char SSID_len, const unsigned char channel);
196 //0 passive mode, 1 active mode, scan time(unit is second)
197 int rda5981_scan_v2(const char *SSID, const unsigned char SSID_len, const unsigned char channel, const unsigned char mode, \
198  const unsigned char scan_time);
199 int rda5981_get_scan_num();
200 int rda5981_get_scan_result(rda5981_scan_result *buf, const unsigned char len);
201 int rda5981_get_scan_result_index(rda5981_scan_result *buf, const unsigned char index);
202 int rda5981_get_scan_result_name(rda5981_scan_result *buf, const char *name);
203 int rda5981_get_scan_result_bssid(rda5981_scan_result *buf, const unsigned char *bssid);
204 int rda5981_check_scan_result_name(const char *name);
205 int rda5981_check_scan_result(const char *ssid, const char *bssid, const unsigned channel);
206 int rda5981_check_scan_result_name_bssid(const unsigned char *name, const unsigned char *bssid);
207 int rda5981_del_scan_all_result(void);
208 void rda5981_set_expired_time(unsigned int expired_time);
209 int rda5981_get_joined_AP(rda5981_scan_result *bss);
210 s8 rda5981_get_rssi();
211 void rda5981_set_main_queue(void* queue);
212 
213 void rda5981_set_sta_listen_interval(unsigned char interval);
214 void rda5981_set_sta_link_loss_time(unsigned char time);
215 unsigned int rda5981_get_ap_join_info(rda5981_apsta_info *buf, const unsigned char len);
216 void rda5981_set_AP_white_list(unsigned char flag, unsigned char *mac);
217 int wland_set_joined_sta_ip(char *mac, unsigned int ip);
218 
219 /*
220  * return 0:ok, else:error.
221  */
222 int rda5981_flash_read_mac_addr(unsigned char *mac_addr);
223 int rda5981_flash_write_mac_addr(unsigned char *mac_addr);
224 
225 /*
226  * return 0:ok, else:error.
227  */
228 int rda5981_flash_erase_uart(void);
229 int rda5981_flash_read_uart(unsigned int *uart);
230 int rda5981_flash_write_uart(unsigned int *uart);
231 
232 /*
233  * return 0:ok, else:error.
234  */
235 int rda5981_flash_read_ip_addr(unsigned char *ip_addr, unsigned char *server_addr);
236 int rda5981_flash_write_ip_addr(unsigned char *ip_add, unsigned char *server_addr);
237 
238 /*
239  * return 0:ok, else:error.
240  */
241 int rda5981_flash_erase_dhcp_data(void);
242 int rda5981_flash_read_dhcp_data(unsigned int *enable, unsigned int *ip, unsigned int *msk, unsigned int *gw);
243 int rda5981_flash_write_dhcp_data(unsigned int enable, unsigned int ip, unsigned int msk, unsigned int gw);
244 
245 /*
246  * return 0:ok, else:error.
247  */
248 int rda5981_flash_read_ap_data(char *ssid, char *passwd, unsigned char *channel);
249 int rda5981_flash_write_ap_data(const char *ssid, const char *passwd, unsigned char channel);
250 int rda5981_flash_erase_ap_data(void);
251 
252 /*
253  * return 0:ok, else:error.
254  */
255 int rda5981_flash_read_ap_net_data(unsigned int *ip, unsigned int *msk, unsigned int *gw,
256  unsigned int *dhcps, unsigned int *dhcpe);
257 int rda5981_flash_write_ap_net_data(unsigned int ip, unsigned int msk, unsigned int gw,
258  unsigned int dhcps, unsigned int dhcpe);
259 int rda5981_flash_erase_ap_net_data(void);
260 
261 /*
262  * return 0:ok, else:error.
263  */
264 int rda5981_flash_read_sta_data(char *ssid, char *passwd);
265 int rda5981_flash_write_sta_data(const char *ssid, const char *passwd);
266 int rda5981_flash_erase_sta_data(void);
267 
268 
269 /*
270  * read 3rd parter data length from flash
271  * return user data length
272  */
273 int rda5981_flash_read_3rdparter_data_length(void);
274 
275 /*
276  * read 3rd parter data from flash
277  * @buf, buf to store user data
278  * @buf_len, length of buf
279  * return user data length
280  */
281 int rda5981_flash_read_3rdparter_data(unsigned char *buf, unsigned int buf_len);
282 
283 /*
284  * write 3rd parter data from flash
285  * @buf, data to write
286  * @buf_len, length of buf.
287  * return 0:ok, else:fail
288  */
289 int rda5981_flash_write_3rdparter_data(const unsigned char *buf, unsigned int buf_len);
290 
291 /*
292  * erase 3rd parter data from flash
293  * return 0:ok, else:fail
294  */
295 int rda5981_flash_erase_3rdparter_data(void);
296 
297 /*
298  * set flash size
299  * @size, 1MB:0x100000, 2MB:0x200000, 4MB:0x400000. default size: 1MB
300  * return 0:ok, else:fail
301  */
302 int rda5981_set_flash_size(const unsigned int size);
303 
304 /*
305  * set userdata location on flash
306  * @sys_data_addr, data to save system parameter, user can not operate this area directly.
307  * size:4KB. default location:0x180fb000
308  * @user_data_addr, data to save user data. user can save own data in this area
309  * by @rda5981_flash_read_3rdparter_data
310  * and @rda5981_flash_write_3rdparter_data
311  * default location:0x180fc000
312  * @user_data_len, user data length, default:4KB
313  * return 0:ok, else:fail
314  */
315 int rda5981_set_user_data_addr(const unsigned int sys_data_addr,
316  const unsigned int user_data_addr, const unsigned int user_data_len);
317 
318 /*
319  * function: erase flash
320  * @addr: mast be 4k alignment
321  * @len: must be 4k alignment. (package 64KB erase and 4KB erase for different condition automatically)
322  * return: 0:success, else:fail
323  */
324 int rda5981_erase_flash(unsigned int addr, unsigned int len);
325 
326 /*
327  * function: write flash
328  * @addr: mast be 256 alignment
329  * @buf: data to be written, best be 4 alignment
330  * @len: buffer len, mast be 4 alignment
331  * return: 0:success, else:fail
332  */
333 int rda5981_write_flash(unsigned int addr, char *buf, unsigned int len);
334 
335 /*
336  * function: read flash to @buf
337  * @addr: best be 4 alignment
338  * @buf: best be 4 alignment
339  * @len: buffer len
340  * return: 0:success, else:fail
341  */
342 int rda5981_read_flash(unsigned int addr, char *buf, unsigned int len);
343 
344 /*
345  * function: read user data
346  * @data: data to read
347  * @len: length of data in byte
348  * @flag: user data flag
349  * return: 0:success, else:fail
350  */
351 int rda5981_read_user_data(unsigned char *data, unsigned short len, unsigned int flag);
352 
353 /*
354  * function: write user data
355  * @data: data to write
356  * @len: length of data in byte
357  * @flag: user data flag
358  * return: 0:success, else:fail
359  */
360 int rda5981_write_user_data(unsigned char *data, unsigned short len, unsigned int flag);
361 
362 /*
363  * function: erase user data
364  * @flag: user data flag
365  * return: 0:success, else:fail
366  */
367 int rda5981_erase_user_data(unsigned int flag);
368 
369 /*
370  * function: update tx power from efuse data, for reg 11F and 120
371  * return: 0:success, else:fail
372  */
373 int update_tx_power_from_efuse(void);
374 
375 /*
376  * function: update xtal calibration from efuse data, for reg DA
377  * return: 0:success, else:fail
378  */
379 int update_xtal_cal_from_efuse(void);
380 
381 /*
382  * function: update mac addr from flash data
383  * return: 0:success, else:fail
384  */
385 int update_mac_addr_from_efuse(void);
386 
387 /*
388  * function: update tx power from flash data, Deprecated version
389  * return: 0:success, else:fail
390  */
391 int update_tx_power_from_flash(void);
392 
393 /*
394  * function: update tx power from flash data, for reg 8A
395  * return: 0:success, else:fail
396  */
397 int update_tx_power_rf_from_flash(void);
398 
399 /*
400  * function: update tx power from flash data, for reg 11F and 120
401  * return: 0:success, else:fail
402  */
403 int update_tx_power_phy_from_flash(void);
404 
405 /*
406  * function: update xtal calibration from flash data
407  * return: 0:success, else:fail
408  */
409 int update_xtal_cal_from_flash(void);
410 
411 /*
412  * function: update mac addr from flash data
413  * return: 0:success, else:fail
414  */
415 int update_mac_addr_from_flash(void);
416 
417 /*
418  * function: write rf reg
419  * @reg: rf reg data
420  * @value: rf reg value
421  * return: 0:success, else:fail
422  * eg: 0x00DA:xtal calibration
423  */
424 int wland_rf_write(unsigned short reg, unsigned short value);
425 
426 /*
427  * function: write rf reg
428  * @reg: rf reg data
429  * @value: rf reg value
430  * @len : value length
431  * return: 0:success, else:fail
432  * eg: 0x008A:tx power rf
433  */
434 int wland_rf_write_all_channels(unsigned short reg, unsigned short *value, unsigned short len);
435 
436 /*
437  * function: read rf reg
438  * @reg: rf reg data
439  * @value: rf reg value
440  * return: 0:success, else:fail
441  */
442 int wland_rf_read(unsigned short reg, unsigned short *value);
443 
444 /*
445  * function: read rf reg
446  * @reg: rf reg data
447  * @value: rf reg value
448  * return: 0:success, else:fail
449  * eg: 0x008A:tx power rf
450  */
451 int wland_rf_read_all_channels(unsigned short reg, unsigned short *value);
452 
453 /*
454  * function: write phy reg
455  * @reg: phy reg data
456  * @value: phy reg value
457  * return: 0:success, else:fail
458  */
459 int wland_phy_write(unsigned int reg, unsigned int value);
460 
461 /*
462  * function: write phy reg
463  * @reg: phy reg data
464  * @value: phy reg value
465  * @len : value length
466  * return: 0:success, else:fail
467  */
468 int wland_phy_write_all_channels(unsigned int reg, unsigned int *value, unsigned short len);
469 
470 /*
471  * function: read phy reg
472  * @reg: phy reg data
473  * @value: phy reg value
474  * return: 0:success, else:fail
475  */
476 int wland_phy_read(unsigned int reg, unsigned int *value);
477 
478 /*
479  * function: read phy reg
480  * @reg: phy reg data
481  * @value: phy reg value
482  * return: 0:success, else:fail
483  */
484 int wland_phy_read_all_channels(unsigned int reg, unsigned int *value);
485 
486 /* efuse API start */
487 /* Efuse CAN ONLY WRITE ONCE! DO NOT CALL THESE API IF YOU DO KNOW WHAT THEY MEANS!!! */
488 
489 /*
490  * function: read all efuse
491  * @value: buffer to store efuse data, 28 bytes
492  * return: 0:success, else:fail
493  */
494 int wland_read_efuse(unsigned char *value);
495 
496 /*
497  * function: read tx power from efuse
498  * @tx_power: 2 bytes, first is mode g/n(range 0x25~0x54), second is mode b(range 0x15~0x54).
499  * return: 0:success, else:fail
500  */
501 int wland_read_tx_power_from_efuse(unsigned char *tx_power);
502 
503 /*
504  * function: read tx power from efuse
505  * @tx_power: 2 bytes, first is mode g/n(range 0x25~0x54), second is mode b(range 0x15~0x54)
506  * @len: must be 2
507  * return: 0:success, else:fail
508  */
509 int wland_write_tx_power_to_efuse(unsigned char *tx_power, unsigned char len);
510 
511 /*
512  * function: read xtal cal from efuse
513  * @xtal_cal: 1 byte, maximum 0x7F
514  * return: 0:success, else:fail
515  */
516 int wland_read_xtal_cal_from_efuse(unsigned char *cal_val);
517 
518 /*
519  * function: write xtal cal to efuse
520  * @xtal_cal: 1 byte, maximum 0x7F
521  * @len : must be 1
522  * return: 0:success, else:fail
523  */
524 int wland_write_xtal_cal_to_efuse(unsigned char *xtal_cal, unsigned char len);
525 
526 /*
527  * function: write mac to efuse
528  * @xtal_cal: 6 bytes
529  * return: 0:success, else:fail
530  */
531 int wland_read_mac_addr_from_efuse(unsigned char *mac_addr);
532 
533 /*
534  * function: write mac to efuse
535  * @xtal_cal: 6 bytes
536  * @len : must be 6
537  * return: 0:success, else:fail
538  */
539 int wland_write_mac_addr_to_efuse(unsigned char*mac_addr, unsigned char len);
540 /* efuse API end */
541 
542 /*
543  * function: start rf test
544  * @argc: number of argv
545  * @argv: args for test, 6 elements for tx test, 4 elements for rx test
546  * @is_tx: 1 for tx test, 0 for rx test
547  * return: 0:success, else:fail
548  */
549 int wland_start_rf_test(unsigned int argc, unsigned int *argv, unsigned int is_tx);
550 
551 /*
552  * function: stop rx test
553  * return: 0:success, else:fail
554  */
555 int wland_stop_rx_test(void);
556 
557 /*
558  * function: get rf test result
559  * @result buffer to store rx result
560  * return: 0:success, else:fail
561  */
562 int wland_get_rx_result(char *result);
563 
564 /*
565  * function: restart rx test, use last rx test args
566  * return: 0:success, else:fail
567  */
568 int wland_restart_rx_test(void);
569 
570 /*
571  * function: stop tx test
572  * return: 0:success, else:fail
573  */
574 int wland_stop_tx_test(void);
575 
576 /*
577  * function: restart tx test, use last tx test args
578  * return: 0:success, else:fail
579  */
580 int wland_restart_tx_test(void);
581 
582 #define RDA5981_FIRMWARE_INFO_ADDR 0x18003000
583 /*
584  * function: reboot to assigned addr (onece).
585  * reboot to rf test mode, not for OTA
586  * @firmware_info_addr: firmware info addr, depend on your flash layout
587  * @reboot_addr: reboot addr, 0x18001000-0x1840000
588  * return: 0:success, else:fail
589  */
590 int rda5981_reboot_to_addr(unsigned int firmware_info_addr, unsigned int reboot_addr);
591 
592 /*
593  * function: read reg and corresponding value related to test mode stored in flash
594  * @reg: reg to read
595  * @value: buffer to store value
596  * @flag: user data flag
597  * return: 0:success, else:fail
598  */
599 int rda5981_read_user_data_regs(unsigned char *reg, unsigned char *value, unsigned int flag);
600 
601 /*
602  * function: write reg and corresponding value related to test mode stored in flash
603  * @reg: reg to write
604  * @value: buffer that stores value
605  * @flag: user data flag
606  * return: 0:success, else:fail
607  */
608 int rda5981_write_user_data_regs(unsigned char *reg, unsigned char *value, unsigned int flag);
609 
610 /*
611  * function: erase reg and corresponding value related to test mode stored in flash
612  * @reg: reg to erase
613  * @flag: user data flag
614  * return: 0:success, else:fail
615  */
616 int rda5981_erase_user_data_regs(unsigned char *reg, unsigned int flag);
617 
618 /*
619  * function: get flash Manufacturer ID
620  * @mid:
621  * return: 0:success, else:fail
622  */
623 int rda5981_flash_get_mid(unsigned char *mid);
624 
625 /*
626  * function: get flash Device ID
627  * @did:
628  * return: 0:success, else:fail
629  */
630 int rda5981_flash_get_did(unsigned char *did);
631 
632 /*
633  * function: get flash ID
634  * @mid:
635  * return: 0:success, else:fail
636  */
637 int rda5981_flash_get_jdid(unsigned short *jdid);
638 
639 /*
640  * function: read mac reg
641  * @reg: mac reg data
642  * @value: mac reg value
643  * return: 0:success, else:fail
644  */
645 int wland_mac_reg_read(unsigned short reg, unsigned int *value);
646 
647 /*
648  * function: write mac reg
649  * @reg: mac reg data
650  * @value: mac reg value
651  * return: 0:success, else:fail
652  */
653 int wland_mac_reg_write(unsigned short reg, unsigned int value);
654 
655 #ifdef __cplusplus
656 }
657 #endif
658 
659 #endif
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.