• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "hdf_wifi_product.h"
10 #include "hdf_wlan_chipdriver_manager.h"
11 #include "hdf_wlan_utils.h"
12 #include "securec.h"
13 
14 #define MAX_WLAN_DEVICE 3
15 /**
16  * @brief Defines the Product Data.
17  *
18  * @since 1.0
19  */
20 struct HdfWifiProductData {
21     char state;                     /* *< WLAN module state */
22     struct WifiModule module;       /* *< Structure of the WLAN module */
23     struct HdfDeviceObject *device; /* *< Structure of the Device Object */
24     struct HdfWlanDevice *wlanDevice[MAX_WLAN_DEVICE];
25 };
26 
27 static struct HdfWifiProductData *g_hdfWlanProductData = NULL;
28 
HdfWlanAddDevice(struct HdfWlanDevice * device)29 int HdfWlanAddDevice(struct HdfWlanDevice *device)
30 {
31     uint8_t i;
32     if (device == NULL) {
33         HDF_LOGE("%s:input is NULL!", __func__);
34         return HDF_FAILURE;
35     }
36     if (g_hdfWlanProductData == NULL) {
37         HDF_LOGE("%s:please Init product first!", __func__);
38         return HDF_FAILURE;
39     }
40     for (i = 0; i < MAX_WLAN_DEVICE; i++) {
41         if (g_hdfWlanProductData->wlanDevice[i] == NULL) {
42             g_hdfWlanProductData->wlanDevice[i] = device;
43             device->id = i;
44             return HDF_SUCCESS;
45         }
46     }
47     HDF_LOGE("%s: device list has full!", __func__);
48     return HDF_FAILURE;
49 }
50 
HdfWlanInitProduct(struct HdfDeviceObject * device,const struct HdfConfigWlanModuleConfig * config)51 int HdfWlanInitProduct(struct HdfDeviceObject *device, const struct HdfConfigWlanModuleConfig *config)
52 {
53     int ret;
54     if (g_hdfWlanProductData != NULL) {
55         HDF_LOGE("%s:already inited!", __func__);
56         return HDF_FAILURE;
57     }
58     g_hdfWlanProductData = OsalMemCalloc(sizeof(struct HdfWifiProductData));
59     if (g_hdfWlanProductData == NULL) {
60         HDF_LOGE("%s:oom", __func__);
61         return HDF_FAILURE;
62     }
63     ret = InitWifiModule(&(g_hdfWlanProductData->module), config);
64     if (ret != HDF_SUCCESS) {
65         HDF_LOGE("%s:InitWifiModule failed! ret=%d", __func__, ret);
66         OsalMemFree(g_hdfWlanProductData);
67         g_hdfWlanProductData = NULL;
68         return ret;
69     }
70     g_hdfWlanProductData->device = device;
71 
72     return HDF_SUCCESS;
73 }
74 
HdfWlanSendBroadcastEvent(uint32_t id,const struct HdfSBuf * data)75 int HdfWlanSendBroadcastEvent(uint32_t id, const struct HdfSBuf *data)
76 {
77     if (g_hdfWlanProductData == NULL) {
78         return HDF_FAILURE;
79     }
80     return HdfDeviceSendEvent(g_hdfWlanProductData->device, id, data);
81 }
82 
HdfWlanGetModule(void)83 struct WifiModule *HdfWlanGetModule(void)
84 {
85     if (g_hdfWlanProductData == NULL) {
86         return NULL;
87     }
88     return &g_hdfWlanProductData->module;
89 }
90 
HdfWlanGetDevice(void)91 struct HdfDeviceObject *HdfWlanGetDevice(void)
92 {
93     if (g_hdfWlanProductData == NULL) {
94         return NULL;
95     }
96     return g_hdfWlanProductData->device;
97 }
98 
HdfWlanGetWlanDevice(uint8_t chipId)99 struct HdfWlanDevice *HdfWlanGetWlanDevice(uint8_t chipId)
100 {
101     if (chipId >= MAX_WLAN_DEVICE || g_hdfWlanProductData == NULL) {
102         return NULL;
103     }
104     return g_hdfWlanProductData->wlanDevice[chipId];
105 }
106 
HdfWlanDeinitProduct(void)107 void HdfWlanDeinitProduct(void)
108 {
109     if (g_hdfWlanProductData != NULL) {
110         OsalMemFree(g_hdfWlanProductData);
111         g_hdfWlanProductData = NULL;
112     }
113 }
114