1/*
2 * Copyright (c) 2021 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 "wifi_hal_ap_feature.h"
17#include "hdf_base.h"
18#include "hdf_log.h"
19#include "securec.h"
20#include "wifi_hal_cmd.h"
21#include "wifi_hal_util.h"
22
23#ifdef __cplusplus
24#if __cplusplus
25extern "C" {
26#endif
27#endif
28
29static int32_t GetAssociatedStasInner(const struct IWiFiAp *apFeature,
30    struct StaInfo *staInfo, uint32_t size, uint32_t *num)
31{
32    if (apFeature == NULL || staInfo == NULL || size == 0 || num == NULL) {
33        HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__);
34        return HDF_ERR_INVALID_PARAM;
35    }
36    return HalCmdGetAssociatedStas(apFeature->baseFeature.ifName, staInfo, size, num);
37}
38
39static int32_t SetCountryCodeInner(const struct IWiFiAp *apFeature, const char *code, uint32_t len)
40{
41    if (apFeature == NULL || code == NULL || len != strlen(code)) {
42        HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__);
43        return HDF_ERR_INVALID_PARAM;
44    }
45    return HalCmdSetCountryCode(apFeature->baseFeature.ifName, code, len);
46}
47
48static int32_t HalGetAssociatedStas(const struct IWiFiAp *apFeature,
49    struct StaInfo *staInfo, uint32_t count, uint32_t *num)
50{
51    HalMutexLock();
52    int32_t ret = GetAssociatedStasInner(apFeature, staInfo, count, num);
53    HalMutexUnlock();
54    return ret;
55}
56
57static int32_t HalSetCountryCode(const struct IWiFiAp *apFeature, const char *code, uint32_t len)
58{
59    HalMutexLock();
60    int32_t ret = SetCountryCodeInner(apFeature, code, len);
61    HalMutexUnlock();
62    return ret;
63}
64
65static int32_t HalGetApBandwidth(const char *ifName, uint8_t *bandwidth)
66{
67    HalMutexLock();
68    int32_t ret = HalCmdGetApBandwidth(ifName, bandwidth);
69    HalMutexUnlock();
70    return ret;
71}
72
73int32_t InitApFeature(struct IWiFiAp **fe)
74{
75    if (fe == NULL || *fe == NULL) {
76        HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__);
77        return HDF_ERR_INVALID_PARAM;
78    }
79    if (InitBaseFeature((struct IWiFiBaseFeature **)fe) != HDF_SUCCESS) {
80        HDF_LOGE("%s: init base feature, line: %d", __FUNCTION__, __LINE__);
81        return HDF_FAILURE;
82    }
83    (*fe)->getAssociatedStas = HalGetAssociatedStas;
84    (*fe)->setCountryCode = HalSetCountryCode;
85    (*fe)->getApBandwidth = HalGetApBandwidth;
86    return HDF_SUCCESS;
87}
88
89#ifdef __cplusplus
90#if __cplusplus
91}
92#endif
93#endif