1/* 2 * Copyright (c) 2022-2023 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 "wpa_callback_impl.h" 17#include <securec.h> 18#include <hdf_base.h> 19#include <hdf_log.h> 20#include <osal_mem.h> 21 22static int32_t WpaCallbackDisconnected(struct IWpaCallback *self, 23 const struct HdiWpaDisconnectParam *disconnectParam, const char *ifName) 24{ 25 (void)self; 26 if (disconnectParam == NULL || ifName == NULL) { 27 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 28 return HDF_ERR_INVALID_PARAM; 29 } 30 HDF_LOGE("WpaCallbackDisconnected: bssid=" MACSTR, MAC2STR(disconnectParam->bssid)); 31 HDF_LOGE("WpaCallbackDisconnected: reasonCode=%{public}d, locallyGenerated=%{public}d", 32 disconnectParam->reasonCode, disconnectParam->reasonCode); 33 return HDF_SUCCESS; 34} 35 36static int32_t WpaCallbackOnConnected(struct IWpaCallback *self, 37 const struct HdiWpaConnectParam *connectParam, const char *ifName) 38{ 39 (void)self; 40 if (connectParam == NULL || ifName == NULL) { 41 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 42 return HDF_ERR_INVALID_PARAM; 43 } 44 HDF_LOGE("WpaCallbackOnConnected: bssid=" MACSTR, MAC2STR(connectParam->bssid)); 45 HDF_LOGE("WpaCallbackOnConnected: networkId=%{public}d", connectParam->networkId); 46 return HDF_SUCCESS; 47} 48 49static int32_t WpaCallbackBssidChanged(struct IWpaCallback *self, 50 const struct HdiWpaBssidChangedParam *bssidChangedParam, const char *ifName) 51{ 52 (void)self; 53 if (bssidChangedParam == NULL || ifName == NULL) { 54 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 55 return HDF_ERR_INVALID_PARAM; 56 } 57 HDF_LOGE("WpaCallbackBssidChanged: bssid=" MACSTR, MAC2STR(bssidChangedParam->bssid)); 58 HDF_LOGE("WpaCallbackBssidChanged: reason=%{public}s", bssidChangedParam->reason); 59 return HDF_SUCCESS; 60} 61 62static int32_t WpaCallbackStateChanged(struct IWpaCallback *self, 63 const struct HdiWpaStateChangedParam *statechangedParam, const char *ifName) 64{ 65 (void)self; 66 if (statechangedParam == NULL || ifName == NULL) { 67 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 68 return HDF_ERR_INVALID_PARAM; 69 } 70 HDF_LOGE("WpaCallbackStateChanged: bssid=" MACSTR, MAC2STR(statechangedParam->bssid)); 71 HDF_LOGE("WpaCallbackStateChanged: status=%{public}d,networkId=%{public}d,ssid=%{public}s", 72 statechangedParam->status, statechangedParam->networkId, statechangedParam->ssid); 73 return HDF_SUCCESS; 74} 75 76static int32_t WpaCallbackTempDisabled(struct IWpaCallback *self, 77 const struct HdiWpaTempDisabledParam *tempDisabledParam, const char *ifName) 78{ 79 (void)self; 80 if (tempDisabledParam == NULL || ifName == NULL) { 81 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 82 return HDF_ERR_INVALID_PARAM; 83 } 84 85 HDF_LOGE("WpaCallbackTempDisabled: networkid=%{public}d,ssid=%{public}s,authFailures=%{public}d, \ 86 duration=%{public}d, reason=%{public}s", tempDisabledParam->networkId, tempDisabledParam->ssid, 87 tempDisabledParam->authFailures, tempDisabledParam->duration, tempDisabledParam->reason); 88 return HDF_SUCCESS; 89} 90 91static int32_t WpaCallbackAssociateReject(struct IWpaCallback *self, 92 const struct HdiWpaAssociateRejectParam *associateRejectParam, const char *ifName) 93{ 94 (void)self; 95 if (associateRejectParam == NULL || ifName == NULL) { 96 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 97 return HDF_ERR_INVALID_PARAM; 98 } 99 HDF_LOGE("WpaCallbackAssociateReject: bssid=" MACSTR, MAC2STR(associateRejectParam->bssid)); 100 HDF_LOGE("WpaCallbackAssociateReject: statusCode=%{public}d,timeOut=%{public}d", 101 associateRejectParam->statusCode, associateRejectParam->timeOut); 102 return HDF_SUCCESS; 103} 104 105static int32_t WpaCallbackWpsOverlap(struct IWpaCallback *self, const char *ifName) 106{ 107 (void)self; 108 if (ifName == NULL) { 109 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 110 return HDF_ERR_INVALID_PARAM; 111 } 112 113 HDF_LOGE("WpaCallbackWpsOverlap: input successfully"); 114 return HDF_SUCCESS; 115} 116 117static int32_t WpaCallbackWpsTimeout(struct IWpaCallback *self, const char *ifName) 118{ 119 (void)self; 120 if (ifName == NULL) { 121 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 122 return HDF_ERR_INVALID_PARAM; 123 } 124 125 HDF_LOGE("WpaCallbackWpsTimeout: input successfully"); 126 return HDF_SUCCESS; 127} 128 129static int32_t WpaCallbackAuthTimeout(struct IWpaCallback *self, const char *ifName) 130{ 131 (void)self; 132 if (ifName == NULL) { 133 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 134 return HDF_ERR_INVALID_PARAM; 135 } 136 137 HDF_LOGE("WpaCallbackAuthTimeout: input successfully"); 138 return HDF_SUCCESS; 139} 140 141static int32_t WpaCallbackScanResult(struct IWpaCallback *self, 142 const struct HdiWpaRecvScanResultParam *recvScanResultParamconst, const char *ifName) 143{ 144 (void)self; 145 if (ifName == NULL || recvScanResultParamconst ==NULL) { 146 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 147 return HDF_ERR_INVALID_PARAM; 148 } 149 150 HDF_LOGE("WpaCallbackScanResult: scanId=%{public}d", recvScanResultParamconst->scanId); 151 return HDF_SUCCESS; 152} 153 154static int32_t WpaCallbackAuthReject(struct IWpaCallback *self, 155 const struct HdiWpaAuthRejectParam *authRejectParam, const char *ifName) 156{ 157 (void)self; 158 if (ifName == NULL || authRejectParam == NULL) { 159 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 160 return HDF_ERR_INVALID_PARAM; 161 } 162 HDF_LOGI("WpaCallbackAuthReject: bssid=" MACSTR " statusCode=%{public}hd,authType=%{public}hd,authTransaction=" 163 "%{public}hd", MAC2STR(authRejectParam->bssid), authRejectParam->statusCode, authRejectParam->authType, 164 authRejectParam->authTransaction); 165 return HDF_SUCCESS; 166} 167 168struct IWpaCallback *WpaCallbackServiceGet(void) 169{ 170 struct WpaCallbackService *service = 171 (struct WpaCallbackService *)OsalMemCalloc(sizeof(struct WpaCallbackService)); 172 if (service == NULL) { 173 HDF_LOGE("%{public}s: malloc WpaCallbackService obj failed!", __func__); 174 return NULL; 175 } 176 177 service->interface.OnEventDisconnected = WpaCallbackDisconnected; 178 service->interface.OnEventConnected = WpaCallbackOnConnected; 179 service->interface.OnEventBssidChanged = WpaCallbackBssidChanged; 180 service->interface.OnEventStateChanged = WpaCallbackStateChanged; 181 service->interface.OnEventTempDisabled = WpaCallbackTempDisabled; 182 service->interface.OnEventAssociateReject = WpaCallbackAssociateReject; 183 service->interface.OnEventWpsOverlap = WpaCallbackWpsOverlap; 184 service->interface.OnEventWpsTimeout = WpaCallbackWpsTimeout; 185 service->interface.OnEventAuthTimeout = WpaCallbackAuthTimeout; 186 service->interface.OnEventScanResult = WpaCallbackScanResult; 187 service->interface.OnEventAuthReject = WpaCallbackAuthReject; 188 return &service->interface; 189} 190 191void WpaCallbackServiceRelease(struct IWpaCallback *instance) 192{ 193 struct WpaCallbackService *service = (struct WpaCallbackService *)instance; 194 if (service == NULL) { 195 return; 196 } 197 198 OsalMemFree(service); 199} 200