1 /*
2  * Copyright (c) 2022 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 <stdlib.h>
17 
18 #include "hdf_log.h"
19 #include "securec.h"
20 #include "sbuf_common_adapter.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 struct HdfIoService *g_wifiService = NULL;
29 
InitWifiService(const char * serviceName)30 struct HdfIoService *InitWifiService(const char *serviceName)
31 {
32     g_wifiService = HdfIoServiceBind(serviceName);
33     return g_wifiService;
34 }
35 
GetWifiService(void)36 struct HdfIoService *GetWifiService(void)
37 {
38     return g_wifiService;
39 }
40 
ReleaseWifiService(void)41 void ReleaseWifiService(void)
42 {
43     if (g_wifiService != NULL) {
44         HdfIoServiceRecycle(g_wifiService);
45         g_wifiService = NULL;
46     }
47 }
48 
SendCmdSync(const uint32_t cmd,struct HdfSBuf * reqData,struct HdfSBuf * respData)49 int32_t SendCmdSync(const uint32_t cmd, struct HdfSBuf *reqData, struct HdfSBuf *respData)
50 {
51     if (reqData == NULL) {
52         HDF_LOGE("%s: params is NULL", __FUNCTION__);
53         return RET_CODE_INVALID_PARAM;
54     }
55     if (g_wifiService == NULL || g_wifiService->dispatcher == NULL ||
56         g_wifiService->dispatcher->Dispatch == NULL) {
57         HDF_LOGE("%s:bad remote service found!", __FUNCTION__);
58         return RET_CODE_MISUSE;
59     }
60     int32_t ret = g_wifiService->dispatcher->Dispatch(&g_wifiService->object, cmd, reqData, respData);
61     HDF_LOGI("%s: cmd=%u, ret=%d", __FUNCTION__, cmd, ret);
62     return ret;
63 }
64 
65 #ifdef __cplusplus
66 #if __cplusplus
67 }
68 #endif
69 #endif