• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: Function related to wifi aware(NAN) feature.
15  */
16 
17 #ifndef __HMAC_SDP_H__
18 #define __HMAC_SDP_H__
19 
20 #include "hmac_vap.h"
21 #include "frw_hmac.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define NAN_INTERVAL_VALUE      512
30 #define NAN_IE_ID               0xDD /* NAN同步帧IE id */
31 #define NAN_PERIOD_SMALL        128 /* 最小值用于建立同步窗口 */
32 
33 #define SDP_TYPE_PUBLISH        0
34 #define SDP_TYPE_SUBSCRIBE      1
35 #define SDP_TYPE_FOLLOWUP       2
36 #define SDP_TYPE_MASK           0x03
37 #define SDP_HAS_DATA_MASK       0x10
38 #define SDP_SRV_ATTR_HDR_LEN    3
39 #define SDP_SRV_DESC_ATTR_ID    0x03 /* SDP 服务属性ID */
40 #define SDP_SRV_CTRL_OFFSET     11
41 
42 #define NAN_DW_ADJ_DLY_CNT      2
43 #define NAN_DW_ADJ_START        20
44 #define NAN_DW_ADJ_MAX          60
45 #define NAN_DW_ADJ_STEP         20
46 
47 #define SDP_PRI_INFO_TYPE_DW    1
48 #define SDP_PRI_INFO_TYPE_SLEEP 2
49 #define SDP_PRI_INFO_TYPE_LEN   4
50 #define SDP_PRI_INFO_LEN        19
51 
52 #define SDP_LOW_POWER_RETRIES   200
53 
54 #define HMAC_SDP_EN_SC 2  /* enable sdp and switch channel test */
55 #define HMAC_SDP_ENABLE 1  /* enable sdp */
56 
57 #define SERVICE_DESCRIPTOR_ATTR_ID 0x03
58 #define COUNTRY_CODE_ATTR_ID 0x0B
59 #define SERVICE_DESCRIPTOR_EXT_ATTR_ID 0x0E
60 #define DEVICE_CAP_ATTR_ID 0x0F
61 #define NAN_AVAILABILITY_ATTR_ID 0x12
62 #define RANGING_INFO_ATTR_ID 0x1A
63 #define VENDOR_SPECIFIC_ATTR_ID 0xDD
64 #define HMAC_MAX_SUBSCRIBE_NUM 1
65 #define HMAC_MAX_PUBLISH_NUM 0
66 #define HMAC_MAX_BUFFER_NUM 8
67 #define HMAC_SDP_TYPE_PUBLISH 0
68 #define HMAC_SDP_TYPE_SUBSCRIBE 1
69 #define HMAC_SDP_TYPE_FOLLOWUP 2
70 #define HMAC_SDP_TYPE_SWITCH_LENGTH 4
71 #define HMAC_SDP_TYPE_MASK 0x03
72 #define HMAC_SDP_HAS_DATA_MASK 0x10
73 #define MAC_ATTR_HDR_LEN 3
74 #define HMAC_SDP_NO_DATA_LEN 10
75 #define HMAC_SDP_TX_UESR_ID 0xF
76 #define HMAC_PUBLISH_TIMEOUT 400 /* publish报文发送间隔时间*ms */
77 
78 #define SDP_SERVICE_NAME_LEN   6
79 
80 #define SDP_HASH_SERVICE_NAME_LEN 6
81 #define WAL_SDP_EN_SC 2  /* enable sdp and switch channel test */
82 #define WAL_SDP_ENABLE 1  /* enable sdp */
83 #define WAL_SDP_DISABLE 0 /* disable sdp */
84 
85 #define WAL_SDP_BEACON_SWITCH_ENABLE 1  /* enable beacon switch */
86 #define WAL_SDP_BEACON_SWITCH_DISABLE 0 /* disable beacon switch */
87 
88 enum OAL_SDP_SERVICE_TYPE {
89     OAL_SDP_SERVICE_TYPE_DEFAULT = 0,    /* 默认值 */
90     OAL_SDP_SERVICE_TYPE_PUBLISH = 1,    /* 对外发布服务 */
91     OAL_SDP_SERVICE_TYPE_SUBSCRIBE = 2,  /* 订阅外部服务 */
92     OAL_SDP_SERVICE_TYPE_GET_PUBLISH = 4 /* 收到外部发布服务消息 */
93 };
94 
95 typedef struct {
96     osal_u8 name[SDP_HASH_SERVICE_NAME_LEN];
97     osal_u16 rsv;
98     osal_u8 *data;
99     osal_u8 len;
100     osal_u8 local_handle;
101     osal_u8 peer_handle;
102     osal_u8 rsv_id;
103 } oal_sdp_info;
104 
105 typedef struct {
106     osal_u8 name[SDP_HASH_SERVICE_NAME_LEN];
107     osal_u8 local_handle;
108     osal_u8 type;
109 } oal_sdp_service;
110 
111 typedef struct {
112     osal_u16 dw_time;
113     osal_u16 prd_time;
114     osal_u16 prd_pre_time;
115     osal_u16 rsvp[2]; /* 2 预留 */
116 } oal_sdp_dw_prd_time_info;
117 
118 typedef struct {
119     osal_u8 attr_len;
120     osal_u8 total_type;
121     osal_u8 total_len;
122     osal_u8 type;
123     osal_u32 total_period;
124     osal_u8 wake_type;
125     osal_u8 wake_len;
126     osal_u16 wake_rsv;
127     osal_u32 wake_period;
128     osal_u8 is_connected;
129     osal_u8 ratio;
130     osal_u8 resv[2];
131 } oal_sdp_wakeup_info;
132 
133 typedef struct {
134     osal_u8 attr_len;
135     osal_u8 total_type;
136     osal_u8 total_len;
137     osal_u8 type;
138     osal_u8 name[SDP_HASH_SERVICE_NAME_LEN];
139     osal_u8 local_handle;
140     osal_u8 resv[9];
141 } oal_sdp_subscribe_info; /* 为了跟 oal_sdp_wakeup_info 结构大小一致 */
142 
143 enum hmac_sdp_pos {
144     HMAC_SDP_POS_PEER_HANDLE = 6,
145     HMAC_SDP_POS_LOCAL_HANDLE,
146     HMAC_SDP_POS_TYPE,
147     HMAC_SDP_POS_DATA_LEN
148 };
149 
150 typedef struct {
151     osal_u8 category;
152     osal_u8 action_code;
153     osal_u8 oui[MAC_OUI_LEN];
154     osal_u8 type;
155 } sdp_action_header;
156 
157 typedef struct {
158     osal_u8 attr_id;
159     osal_u8 attr_len_low;
160     osal_u8 attr_len_high;
161     osal_u8 service_name[SDP_HASH_SERVICE_NAME_LEN];
162     osal_u8 local_handle;
163     osal_u8 peer_handle;
164     osal_u8 svc_ctrl;
165     osal_u8 info_len;
166 } hmac_sdp_descriptor_attr;
167 
168 typedef struct {
169     oal_sdp_service info[HMAC_MAX_PUBLISH_NUM + HMAC_MAX_SUBSCRIBE_NUM];
170     hmac_vap_stru *mac_vap;
171 } hmac_sdp_service_info;
172 
173 typedef struct {
174     osal_u8 srv_name[SDP_SERVICE_NAME_LEN];
175     osal_u8 handle;
176     osal_u8 rsv;
177 } sdp_srv_info;
178 
179 typedef struct {
180     oal_netbuf_stru *netbuf;
181 } hmac_sdp_tx_stru;
182 
183 osal_s32 hmac_sdp_send_data(hmac_vap_stru *hmac_vap, frw_msg *msg);
184 osal_s32 hmac_sdp_start_subscribe(hmac_vap_stru *hmac_vap, frw_msg *msg);
185 osal_s32 hmac_sdp_cancel_subscribe(hmac_vap_stru *hmac_vap, frw_msg *msg);
186 osal_s32 hmac_sdp_init_enable(hmac_vap_stru *hmac_vap, frw_msg *msg);
187 osal_u32 hmac_sdp_init(hmac_vap_stru *hmac_vap, osal_bool switch_channel, osal_u16 peroid, osal_u8 *input_ratio);
188 osal_u32 hmac_sdp_deinit(hmac_vap_stru *hmac_vap);
189 oal_bool_enum hmac_sdp_is_init(osal_void);
190 osal_u8 hmac_is_sdp_frame(oal_netbuf_stru *netbuf);
191 osal_u32 hmac_sdp_proc_rx_mgmt(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf, oal_bool_enum_uint8 *reported_host);
192 const hmac_sdp_service_info *hmac_sdp_get_service_info(osal_void);
193 
194 osal_u8 *hmac_sdp_parse_rx(oal_netbuf_stru *netbuf, oal_sdp_info *sdp_param);
195 osal_s32 hmac_sdp_test(hmac_vap_stru *hmac_vap, frw_msg *msg);
196 osal_s32 hmac_sdp_add_peer_mac(hmac_vap_stru *hmac_vap, frw_msg *msg);
197 osal_s32 hmac_sdp_dw_prd_time_cfg(hmac_vap_stru *hmac_vap, frw_msg *msg);
198 osal_u32 hmac_sdp_send_followup_to_host(const hmac_vap_stru *hmac_vap, oal_sdp_info *sdp_info, osal_u8 *data,
199     osal_u8 len);
200 
201 typedef oal_bool_enum (*hmac_sdp_is_init_cb)(osal_void);
202 typedef osal_u8 (*hmac_is_sdp_frame_cb)(oal_netbuf_stru *netbuf);
203 typedef osal_u32 (*hmac_sdp_proc_rx_mgmt_cb)(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf,
204     oal_bool_enum_uint8 *reported_host);
205 
206 osal_void hmac_sdp_feature_hook_register(osal_void);
207 osal_void hmac_sdp_feature_hook_unregister(osal_void);
208 
209 static osal_u32 hmac_sdp_init_weakref(osal_void) __attribute__ ((weakref("hmac_sdp_msg_init"), used));
210 static osal_void hmac_sdp_deinit_weakref(osal_void) __attribute__ ((weakref("hmac_sdp_msg_deinit"), used));
211 
212 #ifdef __cplusplus
213 #if __cplusplus
214     }
215 #endif
216 #endif
217 
218 #endif /* end of hmac_sdp.h */
219 
220