1 /*
2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3 * This file contains confidential and proprietary information of
4 * OSWare Technology Co., Ltd
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 #include "hdf_device_desc.h"
19 #include "hdf_wifi_product.h"
20 #include "hdf_log.h"
21 #include "osal_mem.h"
22 #include "hdf_wlan_chipdriver_manager.h"
23 #include "securec.h"
24 #include "wifi_module.h"
25
26 #define HDF_LOG_TAG Ap6212Driver
27 static const char * const AP6212_DRIVER_NAME = "ap6212";
28
29 int32_t InitAp6212Chip(struct HdfWlanDevice *device);
30 int32_t DeinitAp6212Chip(struct HdfWlanDevice *device);
31 int32_t Ap6212Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
32 int32_t Ap6212Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
33 void ApMac80211Init(struct HdfChipDriver *chipDriver);
34
BuildAp6212Driver(struct HdfWlanDevice * device,uint8_t ifIndex)35 static struct HdfChipDriver *BuildAp6212Driver(struct HdfWlanDevice *device, uint8_t ifIndex)
36 {
37 struct HdfChipDriver *specificDriver = NULL;
38
39 HDF_LOGE("%s: Enter ", __func__);
40
41 if (device == NULL) {
42 HDF_LOGE("%s fail : channel is NULL", __func__);
43 return NULL;
44 }
45 (void)device;
46 (void)ifIndex;
47 specificDriver = (struct HdfChipDriver *)OsalMemCalloc(sizeof(struct HdfChipDriver));
48 if (specificDriver == NULL) {
49 HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
50 return NULL;
51 }
52 if (memset_s(specificDriver, sizeof(struct HdfChipDriver), 0, sizeof(struct HdfChipDriver)) != EOK) {
53 HDF_LOGE("%s fail: memset_s fail!", __func__);
54 OsalMemFree(specificDriver);
55 return NULL;
56 }
57
58 if (strcpy_s(specificDriver->name, MAX_WIFI_COMPONENT_NAME_LEN, AP6212_DRIVER_NAME) != EOK) {
59 HDF_LOGE("%s fail : strcpy_s fail", __func__);
60 OsalMemFree(specificDriver);
61 return NULL;
62 }
63 specificDriver->init = Ap6212Init;
64 specificDriver->deinit = Ap6212Deinit;
65
66 ApMac80211Init(specificDriver);
67
68 return specificDriver;
69 }
70
ReleaseAp6212Driver(struct HdfChipDriver * chipDriver)71 static void ReleaseAp6212Driver(struct HdfChipDriver *chipDriver)
72 {
73 HDF_LOGE("%s: Enter ", __func__);
74 return;
75
76 if (chipDriver == NULL) {
77 return;
78 }
79 if (strcmp(chipDriver->name, AP6212_DRIVER_NAME) != 0) {
80 HDF_LOGE("%s:Not my driver!", __func__);
81 return;
82 }
83 OsalMemFree(chipDriver);
84 }
85
GetAp6212GetMaxIFCount(struct HdfChipDriverFactory * factory)86 static uint8_t GetAp6212GetMaxIFCount(struct HdfChipDriverFactory *factory)
87 {
88 (void)factory;
89 HDF_LOGE("%s: Enter ", __func__);
90
91 return 1;
92 }
93
94 /* ap6212's register */
HDFWlanRegApDriverFactory(void)95 static int32_t HDFWlanRegApDriverFactory(void)
96 {
97 static struct HdfChipDriverFactory tmpFactory = { 0 };
98 struct HdfChipDriverManager *driverMgr = NULL;
99
100 HDF_LOGE("%s: Enter ", __func__);
101 driverMgr = HdfWlanGetChipDriverMgr();
102 if (driverMgr == NULL) {
103 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
104 return HDF_FAILURE;
105 }
106 tmpFactory.driverName = AP6212_DRIVER_NAME;
107 tmpFactory.GetMaxIFCount = GetAp6212GetMaxIFCount;
108 tmpFactory.InitChip = InitAp6212Chip;
109 tmpFactory.DeinitChip = DeinitAp6212Chip;
110 tmpFactory.Build = BuildAp6212Driver;
111 tmpFactory.Release = ReleaseAp6212Driver;
112 tmpFactory.ReleaseFactory = NULL;
113 if (driverMgr->RegChipDriver(&tmpFactory) != HDF_SUCCESS) {
114 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
115 return HDF_FAILURE;
116 }
117
118 return HDF_SUCCESS;
119 }
120
HdfWlanApChipDriverInit(struct HdfDeviceObject * device)121 static int32_t HdfWlanApChipDriverInit(struct HdfDeviceObject *device)
122 {
123 (void)device;
124 HDF_LOGE("%s: Enter ", __func__);
125 return HDFWlanRegApDriverFactory();
126 }
127
HdfWlanApDriverBind(struct HdfDeviceObject * dev)128 static int HdfWlanApDriverBind(struct HdfDeviceObject *dev)
129 {
130 (void)dev;
131 HDF_LOGE("%s: Enter ", __func__);
132 return HDF_SUCCESS;
133 }
134
HdfWlanApChipRelease(struct HdfDeviceObject * object)135 static void HdfWlanApChipRelease(struct HdfDeviceObject *object)
136 {
137 (void)object;
138 HDF_LOGE("%s: Enter ", __func__);
139 }
140
141 struct HdfDriverEntry g_hdfapchipentry = {
142 .moduleVersion = 1,
143 .Bind = HdfWlanApDriverBind,
144 .Init = HdfWlanApChipDriverInit,
145 .Release = HdfWlanApChipRelease,
146 .moduleName = "HDF_WLAN_CHIPS"
147 };
148
149 HDF_INIT(g_hdfapchipentry);
150