1 /* 2 * Copyright (c) 2024 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 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 struct WifiDirectStatusListener { 26 void (*onLocalRoleChange)(enum WifiDirectRole oldRole, enum WifiDirectRole newRole); 27 void (*onDeviceOnLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource); 28 void (*onDeviceOffLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, const char *localIp); 29 void (*onConnectedForSink)(const struct WifiDirectSinkLink *link); 30 void (*onDisconnectedForSink)(const struct WifiDirectSinkLink *link); 31 }; 32 33 typedef void (*SyncPtkListener)(const char *remoteDeviceId, int result); 34 struct WifiDirectEnhanceManager { 35 int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk); 36 int32_t (*syncPTK)(const char *remoteDeviceId); 37 void (*stopCustomListening)(void); 38 }; 39 40 struct WifiDirectManager { 41 uint32_t (*getRequestId)(void); 42 int32_t (*allocateListenerModuleId)(void); 43 void (*freeListenerModuleId)(int32_t moduleId); 44 45 int32_t (*connectDevice)(struct WifiDirectConnectInfo *info, struct WifiDirectConnectCallback *callback); 46 int32_t (*cancelConnectDevice)(const struct WifiDirectConnectInfo *info); 47 int32_t (*disconnectDevice)(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback); 48 int32_t (*forceDisconnectDevice)( 49 struct WifiDirectForceDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback); 50 void (*registerStatusListener)(struct WifiDirectStatusListener *listener); 51 int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType); 52 bool (*isNoneLinkByType)(enum WifiDirectLinkType linkType); 53 54 bool (*isNegotiateChannelNeeded)(const char *remoteNetworkId, enum WifiDirectLinkType linkType); 55 void (*refreshRelationShip)(const char *remoteUuid, const char *remoteMac); 56 bool (*linkHasPtk)(const char *remoteDeviceId); 57 int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk); 58 int32_t (*syncPTK)(const char *remoteDeviceId); 59 void (*addSyncPtkListener)(SyncPtkListener listener); 60 61 void (*stopCustomListening)(void); 62 63 bool (*isDeviceOnline)(const char *remoteMac); 64 int32_t (*getLocalIpByUuid)(const char *uuid, char *localIp, int32_t localIpSize); 65 int32_t (*getLocalIpByRemoteIp)(const char *remoteIp, char *localIp, int32_t localIpSize); 66 int32_t (*getRemoteUuidByIp)(const char *remoteIp, char *uuid, int32_t uuidSize); 67 int32_t (*getLocalAndRemoteMacByLocalIp)(const char *localIp, char *localMac, size_t localMacSize, char *remoteMac, 68 size_t remoteMacSize); 69 70 bool (*supportHmlTwo)(void); 71 bool (*isWifiP2pEnabled)(void); 72 int (*getStationFrequency)(void); 73 bool (*isHmlConnected)(void); 74 75 int32_t (*init)(void); 76 77 /* for private inner usage */ 78 void (*notifyOnline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource); 79 void (*notifyOffline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, const char *localIp); 80 void (*notifyRoleChange)(enum WifiDirectRole oldRole, enum WifiDirectRole newRole); 81 void (*notifyConnectedForSink)(const struct WifiDirectSinkLink *link); 82 void (*notifyDisconnectedForSink)(const struct WifiDirectSinkLink *link); 83 void (*registerEnhanceManager)(struct WifiDirectEnhanceManager *manager); 84 void (*notifyPtkSyncResult)(const char *remoteDeviceId, int result); 85 }; 86 87 /* singleton */ 88 struct WifiDirectManager* GetWifiDirectManager(void); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 #endif 94