1 /*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
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
16 #include "hi_cipher.h"
17 #include "hi_wifi_api.h"
18 #include "hi_wifi_sdp_api.h"
19 #include "wifiaware.h"
20
HalWifiSdpInit(const char * ifname)21 int HalWifiSdpInit(const char* ifname)
22 {
23 if (hi_wifi_sdp_init(ifname) != HISI_OK) {
24 return -1;
25 }
26 return 0;
27 }
28
HalCipherHashSha256(const char * input,unsigned int inputLen,unsigned char * hash,unsigned hashLen)29 unsigned int HalCipherHashSha256(const char* input, unsigned int inputLen, unsigned char* hash, unsigned hashLen)
30 {
31 if (hi_cipher_hash_sha256((uintptr_t)input, inputLen, hash, hashLen) != HISI_OK) {
32 return -1;
33 }
34 return 0;
35 }
36
HalWifiSdpStartService(const char * svcName,unsigned char localHandle,RecvCallback recvCB,unsigned char role)37 int HalWifiSdpStartService(const char* svcName, unsigned char localHandle, RecvCallback recvCB, unsigned char role)
38 {
39 if (hi_wifi_sdp_start_service(svcName, localHandle, (hi_wifi_sdp_recv_cb)recvCB, role) != HISI_OK) {
40 return -1;
41 }
42 return 0;
43 }
44
HalWifiSdpSend(unsigned char * macAddr,unsigned char peerHandle,unsigned char localHandle,unsigned char * msg,int len)45 int HalWifiSdpSend(unsigned char* macAddr, unsigned char peerHandle, unsigned char localHandle,
46 unsigned char* msg, int len)
47 {
48 if (hi_wifi_sdp_send(macAddr, peerHandle, localHandle, msg, len) != HISI_OK) {
49 return -1;
50 }
51 return 0;
52 }
53
HalWifiSdpStopService(unsigned char localHandle,unsigned char role)54 int HalWifiSdpStopService(unsigned char localHandle, unsigned char role)
55 {
56 if (hi_wifi_sdp_stop_service(localHandle, role) != HISI_OK) {
57 return -1;
58 }
59 return 0;
60 }
61
HalWifiSdpDeinit(void)62 int HalWifiSdpDeinit(void)
63 {
64 if (hi_wifi_sdp_deinit() != HISI_OK) {
65 return -1;
66 }
67 return 0;
68 }
69
HalWifiSdpAdjustTxPower(const char * ifname,signed char power)70 int HalWifiSdpAdjustTxPower(const char *ifname, signed char power)
71 {
72 if (hi_wifi_sdp_adjust_tx_power(ifname, power) != HISI_OK) {
73 return -1;
74 }
75 return 0;
76 }
77
HalWifiSdpRestoreTxPower(const char * ifname)78 int HalWifiSdpRestoreTxPower(const char *ifname)
79 {
80 if (hi_wifi_sdp_restore_tx_power(ifname) != HISI_OK) {
81 return -1;
82 }
83 return 0;
84 }
85
HalWifiSdpBeaconSwitch(const char * ifname,unsigned char enable)86 int HalWifiSdpBeaconSwitch(const char *ifname, unsigned char enable)
87 {
88 if (hi_wifi_sdp_beacon_switch(ifname, enable) != HISI_OK) {
89 return -1;
90 }
91 return 0;
92 }
93
HalWifiSdpSetRetryTimes(unsigned int retries)94 int HalWifiSdpSetRetryTimes(unsigned int retries)
95 {
96 if (hi_wifi_sdp_set_retry_times(retries) != HISI_OK) {
97 return -1;
98 }
99 return 0;
100 }
101
HalWifiSdpGetSyncMode(void)102 int HalWifiSdpGetSyncMode(void)
103 {
104 return hi_wifi_sdp_get_sync_mode();
105 }