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