1 // Copyright (C) 2022 Beken Corporation
2 //
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
15 #include "wifiaware.h"
16
17
18 typedef enum {
19 WIFI_SDP_PUBLISH = 0x01,
20 WIFI_SDP_SUBSCRIBE = 0x02,
21 WIFI_SDP_BUTT
22 }wifi_sdp_type_enum;
23
24 typedef enum {
25 WIFI_SDP_SYNC_MODE_PRIVATE,
26 WIFI_SDP_SYNC_MODE_STANDARD,
27 WIFI_SDP_SYNC_MODE_BOTH,
28 WIFI_SDP_SYNC_MODE_BUTT
29 }wifi_sdp_sync_enum;
30
31 #define WIFI_OK 0
32 #define WIFI_FAIL -1
33
34 typedef int (*bk_wifi_sdp_recv_cb)(unsigned char* mac, unsigned char peer_handle, unsigned char local_handle,
35 unsigned char* msg, unsigned char len);
36 int bk_wifi_sdp_init(const char* ifname);
37 int bk_wifi_sdp_deinit(void);
38 int bk_wifi_sdp_start_service(const char* service_name, unsigned char local_handle,
39 bk_wifi_sdp_recv_cb recv_cb, unsigned char role);
40 int bk_wifi_sdp_stop_service(unsigned char local_handle, unsigned char role);
41 int bk_wifi_sdp_send(unsigned char* mac_addr, unsigned char peer_handle, unsigned char local_handle,
42 unsigned char* msg, int len);
43 int bk_wifi_sdp_adjust_tx_power(const char *ifname, signed char power);
44 int bk_wifi_sdp_restore_tx_power(const char *ifname);
45 int bk_wifi_sdp_adjust_rx_param(const char *ifname, signed char rssi);
46 int bk_wifi_sdp_restore_rx_param(const char *ifname);
47 int bk_wifi_sdp_beacon_switch(const char *ifname, unsigned char enable);
48 int bk_wifi_sdp_set_retry_times(unsigned int retries);
49 int bk_wifi_sdp_get_sync_mode(void);
50
51
bk_wifi_sdp_init(const char * ifname)52 int bk_wifi_sdp_init(const char* ifname) { return WIFI_FAIL; }
bk_wifi_sdp_deinit(void)53 int bk_wifi_sdp_deinit(void) { return WIFI_FAIL; }
bk_wifi_sdp_start_service(const char * service_name,unsigned char local_handle,bk_wifi_sdp_recv_cb recv_cb,unsigned char role)54 int bk_wifi_sdp_start_service(const char* service_name, unsigned char local_handle,
55 bk_wifi_sdp_recv_cb recv_cb, unsigned char role) { return WIFI_FAIL; }
bk_wifi_sdp_stop_service(unsigned char local_handle,unsigned char role)56 int bk_wifi_sdp_stop_service(unsigned char local_handle, unsigned char role) { return WIFI_FAIL; }
bk_wifi_sdp_send(unsigned char * mac_addr,unsigned char peer_handle,unsigned char local_handle,unsigned char * msg,int len)57 int bk_wifi_sdp_send(unsigned char* mac_addr, unsigned char peer_handle, unsigned char local_handle,
58 unsigned char* msg, int len) { return WIFI_FAIL; }
bk_wifi_sdp_adjust_tx_power(const char * ifname,signed char power)59 int bk_wifi_sdp_adjust_tx_power(const char *ifname, signed char power) { return WIFI_FAIL; }
bk_wifi_sdp_restore_tx_power(const char * ifname)60 int bk_wifi_sdp_restore_tx_power(const char *ifname) { return WIFI_FAIL; }
bk_wifi_sdp_adjust_rx_param(const char * ifname,signed char rssi)61 int bk_wifi_sdp_adjust_rx_param(const char *ifname, signed char rssi) { return WIFI_FAIL; }
bk_wifi_sdp_restore_rx_param(const char * ifname)62 int bk_wifi_sdp_restore_rx_param(const char *ifname) { return WIFI_FAIL; }
bk_wifi_sdp_beacon_switch(const char * ifname,unsigned char enable)63 int bk_wifi_sdp_beacon_switch(const char *ifname, unsigned char enable) { return WIFI_FAIL; }
bk_wifi_sdp_set_retry_times(unsigned int retries)64 int bk_wifi_sdp_set_retry_times(unsigned int retries) { return WIFI_FAIL; }
bk_wifi_sdp_get_sync_mode(void)65 int bk_wifi_sdp_get_sync_mode(void) { return WIFI_FAIL; }
66
67 typedef unsigned int uintptr_t;
68 unsigned int hi_cipher_hash_sha256(uintptr_t input, unsigned int input_len, unsigned char *hash, unsigned int hash_len);
hi_cipher_hash_sha256(uintptr_t input,unsigned int input_len,unsigned char * hash,unsigned int hash_len)69 unsigned int hi_cipher_hash_sha256(uintptr_t input, unsigned int input_len, unsigned char *hash, unsigned int hash_len) { return WIFI_FAIL; }
70
71
72
HalWifiSdpInit(const char * ifname)73 int HalWifiSdpInit(const char* ifname)
74 {
75 if (bk_wifi_sdp_init(ifname) != WIFI_OK) {
76 return -1;
77 }
78 return 0;
79 }
80
HalCipherHashSha256(const char * input,unsigned int inputLen,unsigned char * hash,unsigned hashLen)81 unsigned int HalCipherHashSha256(const char* input, unsigned int inputLen, unsigned char* hash, unsigned hashLen)
82 {
83 if (hi_cipher_hash_sha256((uintptr_t)input, inputLen, hash, hashLen) != WIFI_OK) {
84 return -1;
85 }
86 return 0;
87 }
88
HalWifiSdpStartService(const char * svcName,unsigned char localHandle,RecvCallback recvCB,unsigned char role)89 int HalWifiSdpStartService(const char* svcName, unsigned char localHandle, RecvCallback recvCB, unsigned char role)
90 {
91 if (bk_wifi_sdp_start_service(svcName, localHandle, (bk_wifi_sdp_recv_cb)recvCB, role) != WIFI_OK) {
92 return -1;
93 }
94 return 0;
95 }
96
HalWifiSdpSend(unsigned char * macAddr,unsigned char peerHandle,unsigned char localHandle,unsigned char * msg,int len)97 int HalWifiSdpSend(unsigned char* macAddr, unsigned char peerHandle, unsigned char localHandle,
98 unsigned char* msg, int len)
99 {
100 if (bk_wifi_sdp_send(macAddr, peerHandle, localHandle, msg, len) != WIFI_OK) {
101 return -1;
102 }
103 return 0;
104 }
105
HalWifiSdpStopService(unsigned char localHandle,unsigned char role)106 int HalWifiSdpStopService(unsigned char localHandle, unsigned char role)
107 {
108 if (bk_wifi_sdp_stop_service(localHandle, role) != WIFI_OK) {
109 return -1;
110 }
111 return 0;
112 }
113
HalWifiSdpDeinit(void)114 int HalWifiSdpDeinit(void)
115 {
116 if (bk_wifi_sdp_deinit() != WIFI_OK) {
117 return -1;
118 }
119 return 0;
120 }
121
HalWifiSdpAdjustTxPower(const char * ifname,signed char power)122 int HalWifiSdpAdjustTxPower(const char *ifname, signed char power)
123 {
124 if (bk_wifi_sdp_adjust_tx_power(ifname, power) != WIFI_OK) {
125 return -1;
126 }
127 return 0;
128 }
129
HalWifiSdpRestoreTxPower(const char * ifname)130 int HalWifiSdpRestoreTxPower(const char *ifname)
131 {
132 if (bk_wifi_sdp_restore_tx_power(ifname) != WIFI_OK) {
133 return -1;
134 }
135 return 0;
136 }
137
HalWifiSdpBeaconSwitch(const char * ifname,unsigned char enable)138 int HalWifiSdpBeaconSwitch(const char *ifname, unsigned char enable)
139 {
140 if (bk_wifi_sdp_beacon_switch(ifname, enable) != WIFI_OK) {
141 return -1;
142 }
143 return 0;
144 }
145
HalWifiSdpSetRetryTimes(unsigned int retries)146 int HalWifiSdpSetRetryTimes(unsigned int retries)
147 {
148 if (bk_wifi_sdp_set_retry_times(retries) != WIFI_OK) {
149 return -1;
150 }
151 return 0;
152 }
153
HalWifiSdpGetSyncMode(void)154 int HalWifiSdpGetSyncMode(void)
155 {
156 return bk_wifi_sdp_get_sync_mode();
157 }
158