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 #ifndef OHOS_WIFI_HAL_CRPC_SERVER_H
17 #define OHOS_WIFI_HAL_CRPC_SERVER_H
18 
19 #include "server.h" /* RPC Server header file */
20 #include "wifi_hal_define.h"
21 #include "wifi_hal_struct.h"
22 #include "wifi_hal_p2p_struct.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef int (*Rpcfunc)(RpcServer *server, Context *context);
29 
30 typedef struct WifiHalRpcFunc {
31     char funcname[128];
32     Rpcfunc func;
33     struct WifiHalRpcFunc *next;
34 } WifiHalRpcFunc;
35 
36 #define RPC_FUNC_NUM 10
37 #define RPC_FUNCNAME_MAX_LEN 128
38 #define WIFI_COM_STR_LENGTH 512
39 
40 /**
41  * @Description Initialization the function table.
42  *
43  * @return int - 0 Success, -1 Failed.
44  */
45 int InitRpcFunc(void);
46 /**
47  * @Description Release the function table.
48  *
49  */
50 void ReleaseRpcFunc(void);
51 /**
52  * @Description Get the Rpc Func object.
53  *
54  * @param func - Function name string.
55  * @return Rpcfunc - Function pointer found.
56  */
57 Rpcfunc GetRpcFunc(const char *func);
58 
59 /**
60  * @Description Set the Rpc Server Inited object.
61  *
62  * @param server - Pointer to the global structure of the communication server.
63  */
64 void SetRpcServerInited(RpcServer *server);
65 
66 /**
67  * @Description Get the Rpc Server object.
68  *
69  * @return RpcServer*.
70  */
71 RpcServer *GetRpcServer(void);
72 
73 typedef struct WifiHalCbIFaceMsg {
74     int id;
75     int type;
76     char ifname[WIFI_IFACE_NAME_MAXLEN];
77 } WifiHalCbIFaceMsg;
78 
79 typedef struct WifiHalConnectMsg {
80     int status;
81     int networkId;
82     char bssid[WIFI_MAC_LENGTH + 1];
83 } WifiHalConnectMsg;
84 
85 typedef struct WifiHalBssidChangedMsg {
86     char reason[WIFI_REASON_LENGTH];
87     char bssid[WIFI_MAC_LENGTH + 1];
88 } WifiHalBssidChangedMsg;
89 
90 typedef struct WifiHalCommonMsg {
91     char event[WIFI_COM_STR_LENGTH + 1];
92 } WifiHalCommonMsg;
93 
94 typedef union WifiHalCallbackMsg {
95     int scanStatus;
96     WifiHalCommonMsg commsg;
97     WifiHalConnectMsg connMsg;
98     WifiHalCbIFaceMsg ifMsg;
99     P2pDeviceInfo deviceInfo;
100     P2pGroupInfo groupInfo;
101     P2pInvitationInfo invitaInfo;
102     P2pServDiscRespInfo serverInfo;
103     P2pServDiscReqInfo serDiscReqInfo;
104     WifiHalBssidChangedMsg bssidChangedMsg;
105 } WifiHalCallbackMsg;
106 
107 typedef struct WifiHalEventCallbackMsg {
108     WifiHalCallbackMsg msg;
109     struct WifiHalEventCallbackMsg *pre;
110     struct WifiHalEventCallbackMsg *next;
111 } WifiHalEventCallbackMsg;
112 
113 /* Define callback message processing. */
114 typedef struct WifiHalEventCallback {
115     WifiHalEventCallbackMsg cbmsgs[WIFI_HAL_MAX_EVENT - WIFI_FAILURE_EVENT];
116     pthread_mutex_t mutex; /* Message mutex. */
117 } WifiHalEventCallback;
118 
119 /**
120  * @Description Init Tabele of the Callback Msg.
121  *
122  * @return int - 0 Success, -1 Failed.
123  */
124 int InitCallbackMsg(void);
125 /**
126  * @Description Release Table of the Callback Msg.
127  *
128  */
129 void ReleaseCallbackMsg(void);
130 /**
131  * @Description Add an event node to the header of the corresponding event linked list.
132  *
133  * @param event - Event id.
134  * @param msg
135  * @return int - 0 Success, -1 Failed.
136  */
137 int PushBackCallbackMsg(int event, WifiHalEventCallbackMsg *msg);
138 /**
139  * @Description Obtain event nodes from the event list.
140  *
141  * @param event - Event id.
142  * @return int - 0 Success, -1 Failed.
143  */
144 int PopBackCallbackMsg(int event);
145 /**
146  * @Description Obtain the event from the event.
147  *
148  * @param event - Event id.
149  * @return WifiHalEventCallbackMsg*
150  */
151 WifiHalEventCallbackMsg *FrontCallbackMsg(int event);
152 /**
153  * @Description Add an event to the event list.
154  *
155  * @param event - Event id.
156  * @return int - 0 Success, -1 Failed.
157  */
158 int PopFrontCallbackMsg(int event);
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 #endif