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 typedef void (*PtkMismatchListener)(const char *remoteNetworkId, uint32_t len, int32_t reason); 35 struct WifiDirectEnhanceManager { 36 int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk); 37 int32_t (*syncPTK)(const char *remoteDeviceId); 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 int32_t (*forceDisconnectDeviceSync)(enum WifiDirectLinkType wifiDirectLinkType); 51 void (*registerStatusListener)(struct WifiDirectStatusListener *listener); 52 int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType); 53 bool (*isNoneLinkByType)(enum WifiDirectLinkType linkType); 54 55 bool (*isNegotiateChannelNeeded)(const char *remoteNetworkId, enum WifiDirectLinkType linkType); 56 void (*refreshRelationShip)(const char *remoteUuid, const char *remoteMac); 57 bool (*linkHasPtk)(const char *remoteDeviceId); 58 int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk); 59 int32_t (*syncPTK)(const char *remoteDeviceId); 60 void (*addSyncPtkListener)(SyncPtkListener listener); 61 void (*addPtkMismatchListener)(PtkMismatchListener listener); 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 HmlCapabilityCode (*getHmlCapabilityCode)(void); 75 76 int32_t (*init)(void); 77 78 /* for private inner usage */ 79 void (*notifyOnline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource); 80 void (*notifyOffline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, const char *localIp); 81 void (*notifyRoleChange)(enum WifiDirectRole oldRole, enum WifiDirectRole newRole); 82 void (*notifyConnectedForSink)(const struct WifiDirectSinkLink *link); 83 void (*notifyDisconnectedForSink)(const struct WifiDirectSinkLink *link); 84 void (*registerEnhanceManager)(struct WifiDirectEnhanceManager *manager); 85 void (*notifyPtkSyncResult)(const char *remoteDeviceId, int result); 86 void (*notifyPtkMismatch)(const char *remoteNetworkId, uint32_t len, int32_t reason); 87 }; 88 89 /* singleton */ 90 struct WifiDirectManager* GetWifiDirectManager(void); 91 92 #ifdef __cplusplus 93 } 94 #endif 95 #endif 96