• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef WIFI_DIRECT_MANAGER_H
16 #define WIFI_DIRECT_MANAGER_H
17 
18 #include "common_list.h"
19 #include "wifi_direct_types.h"
20 #include "wifi_direct_negotiate_channel.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct WifiDirectStatusListener {
27     void (*onLocalRoleChange)(enum WifiDirectRole myRole);
28     void (*onDeviceOnLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid);
29     void (*onDeviceOffLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid);
30 };
31 
32 struct WifiDirectManager {
33     /* public interface */
34     int32_t (*getRequestId)(void);
35     int32_t (*connectDevice)(struct WifiDirectConnectInfo *connectInfo, struct WifiDirectConnectCallback *callback);
36     int32_t (*disconnectDevice)(struct WifiDirectConnectInfo *connectInfo, struct WifiDirectConnectCallback *callback);
37     void (*registerStatusListener)(struct WifiDirectStatusListener *listener);
38     int32_t (*getRemoteUuidByIp)(const char *ipString, char *uuid, int32_t uuidSize);
39     bool (*isDeviceOnline)(const char *remoteMac);
40     int32_t (*getLocalIpByRemoteIp)(const char *remoteIp, char *localIp, int32_t localIpSize);
41     int32_t (*getLocalIpByUuid)(const char *uuid, char *localIp, int32_t localIpSize);
42 
43     void (*onNegotiateChannelDataReceived)(struct WifiDirectNegotiateChannel *channel, const uint8_t *data, size_t len);
44     void (*onNegotiateChannelDisconnected)(struct WifiDirectNegotiateChannel *channel);
45 
46     /* implement connect callback interface */
47     void (*onConnectSuccess)(int32_t requestId, const struct WifiDirectLink *link);
48     void (*onConnectFailure)(int32_t requestId, enum WifiDirectErrorCode reason);
49     void (*onDisconnectSuccess)(int32_t requestId);
50     void (*onDisconnectFailure)(int32_t requestId, enum WifiDirectErrorCode reason);
51 
52     /* private data member */
53     int32_t requestId;
54     ListNode callbackList;
55     struct WifiDirectStatusListener listener;
56     enum WifiDirectRole myRole;
57     char localMac[MAC_ADDR_STR_LEN];
58 };
59 
60 /* singleton */
61 struct WifiDirectManager* GetWifiDirectManager(void);
62 
63 int32_t WifiDirectManagerInit(void);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 #endif