1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __ZCONFIG_LIB_H__
6 #define __ZCONFIG_LIB_H__
7 
8 #include "os.h"
9 
10 #ifndef ETH_ALEN
11 #define ETH_ALEN (6)
12 #endif
13 
14 #define FRAME_ACTION_MASK     (1 << FRAME_ACTION)
15 #define FRAME_BEACON_MASK     (1 << FRAME_BEACON)
16 #define FRAME_PROBE_REQ_MASK  (1 << FRAME_PROBE_REQ)
17 #define FRAME_PROBE_RESP_MASK (1 << FRAME_PROBE_RESPONSE)
18 #define FRAME_DATA_MASK       (1 << FRAME_DATA)
19 
20 #define ZC_MAX_SSID_LEN \
21     (32 + 1) /* ssid: 32 octets at most, include the NULL-terminated */
22 #define ZC_MAX_PASSWD_LEN (64 + 1) /* 8-63 ascii */
23 #define MAX_APLIST_NUM    (100)
24 #define ZC_MAX_TOKEN_LEN  (16)
25 
26 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
27 extern "C" {
28 #endif
29 
30 enum _ZC_AUTH_TYPE_ {
31     ZC_AUTH_TYPE_OPEN,
32     ZC_AUTH_TYPE_SHARED,
33     ZC_AUTH_TYPE_WPAPSK,
34     ZC_AUTH_TYPE_WPA8021X,
35     ZC_AUTH_TYPE_WPA2PSK,
36     ZC_AUTH_TYPE_WPA28021X,
37     ZC_AUTH_TYPE_WPAPSKWPA2PSK,
38     ZC_AUTH_TYPE_MAX = ZC_AUTH_TYPE_WPAPSKWPA2PSK,
39     ZC_AUTH_TYPE_INVALID = 0xff,
40 };
41 
42 enum _ZC_ENC_TYPE_ {
43     ZC_ENC_TYPE_NONE,
44     ZC_ENC_TYPE_WEP,
45     ZC_ENC_TYPE_TKIP,
46     ZC_ENC_TYPE_AES,
47     ZC_ENC_TYPE_TKIPAES,
48     ZC_ENC_TYPE_MAX = ZC_ENC_TYPE_TKIPAES,
49     ZC_ENC_TYPE_INVALID = 0xff,
50 };
51 
52 enum _ZC_PKG_TYPE_ {
53     PKG_INVALID,  /* invalid pkg, --无效包 */
54     PKG_BC_FRAME, /* broadcast frame,
55                      --信道扫描阶段,收到收到该返回值建议延长在当前信道停留时间,可以延长T1
56                    */
57     PKG_START_FRAME, /* start frame, --信道扫描阶段,收到该返回值用于锁定信道 */
58     PKG_DATA_FRAME,   /* data frame,
59                          --数据包,锁定信道后长时间T2收不到数据包,需重新进入扫描阶段
60                        */
61     PKG_ALINK_ROUTER, /* alink router */
62     PKG_GROUP_FRAME,  /* group frame */
63     PKG_MCAST_FRAME,  /* group frame */
64     PKG_END /* --配网结束事件,已拿到ssid和passwd,通过回调函数去获取ssid和passwd
65              */
66     /*
67      * 参考值:
68      * T1:             400ms >= T2 >= 100ms
69      * T2:             3s
70      */
71 };
72 
73 /*进入monitor模式前后调用该函数 */
74 void zconfig_init();
75 /* 配网成功后,调用该函数,释放内存资源 */
76 void zconfig_destroy(void);
77 /*
78     进入monitor/sniffer模式后,将收到的包传给该函数进行处理
79     若进入monitor时进行包过滤配置,以下几种包不能过滤:
80     1) 数据包,目的地址为广播地址
81     2) 长度>40的管理帧
82     厂家需要自行切换信道,切信道时间按照自身平台需要进行调整,建议取值范围[100ms
83    - 300ms] 其中,6号信道需作为固定信道放在信道列表里!!! input: pkt_data:
84    80211 wireless raw package, include data frame & management frame pkt_length:
85    radio_hdr + 80211 hdr + payload, without fcs(4B) return: 见enum
86    _PKG_TYPE_结构体说明
87 */
88 int zconfig_recv_callback(void *pkt_data, uint32_t pkt_length, uint8_t channel,
89                           int link_type, int with_fcs, signed char rssi);
90 
91 /*
92  * save apinfo
93  * 0 -- success, otherwise, failed.
94  */
95 int zconfig_set_apinfo(uint8_t *ssid, uint8_t *bssid, uint8_t channel,
96                        uint8_t auth, uint8_t pairwise_cipher,
97                        uint8_t group_cipher, signed char rssi);
98 
99 uint8_t zconfig_get_lock_chn(void);
100 
101 /* add channel to global scanning channel list */
102 int zconfig_add_active_channel(int channel);
103 /* channel locked callback */
104 void zconfig_channel_locked_callback(uint8_t primary_channel,
105                                      uint8_t secondary_channel, uint8_t *bssid);
106 /* got ssid&passwd callback */
107 void zconfig_got_ssid_passwd_callback(uint8_t *ssid, uint8_t *passwd,
108                                       uint8_t *bssid, uint8_t *token,
109                                       uint8_t auth, uint8_t encry,
110                                       uint8_t channel);
111 void zconfig_force_rescan(void);
112 void aws_set_dst_chan(int channel);
113 void aws_switch_channel(void);
114 void aws_release_mutex(void);
115 
116 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
117 }
118 #endif
119 
120 #endif
121