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 P2PLINK_INTERFACE_H 17 #define P2PLINK_INTERFACE_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #include "p2plink_type.h" 23 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 typedef struct { 31 void (*onConnected)(int32_t requestId, const char *myIp, const char *peerIp); 32 void (*onConnectFailed)(int32_t requestId, int32_t reason); 33 } P2pLinkCb; 34 35 typedef struct { 36 int32_t requestId; 37 int64_t authId; 38 char peerMac[P2P_MAC_LEN]; 39 P2pLinkRole expectedRole; 40 int pid; 41 P2pLinkCb cb; 42 } P2pLinkConnectInfo; 43 44 typedef struct { 45 int64_t authId; 46 char peerMac[P2P_MAC_LEN]; 47 int pid; 48 } P2pLinkDisconnectInfo; 49 50 typedef struct { 51 void (*onMyRoleChange)(P2pLinkRole myRole); 52 void (*onDevOffline)(const char *peerMac); 53 } P2pLinkPeerDevStateCb; 54 55 typedef struct { 56 P2pLinkRole peerRole; 57 P2pLinkRole expectedRole; 58 char peerGoMac[P2P_MAC_LEN]; 59 char peerMac[P2P_MAC_LEN]; 60 bool isBridgeSupported; 61 } RoleIsConflictInfo; 62 63 int32_t P2pLinkGetRequestId(void); 64 int32_t P2pLinkConnectDevice(const P2pLinkConnectInfo *info); 65 int32_t P2pLinkDisconnectDevice(const P2pLinkDisconnectInfo *info); 66 int32_t P2pLinkInit(void); 67 68 void P2pLinkRegPeerDevStateChange(const P2pLinkPeerDevStateCb *cb); 69 int32_t P2pLinkGetLocalIp(char *localIp, int32_t localIpLen); 70 71 int32_t P2pLinkIsRoleConflict(const RoleIsConflictInfo *info); 72 73 int32_t P2pLinkGetPeerMacByPeerIp(const char *peerIp, char *peerMac, int32_t macLen); 74 int32_t P2pLinkQueryDevIsOnline(const char *peerMac); 75 76 #ifdef __cplusplus 77 #if __cplusplus 78 } 79 #endif /* __cplusplus */ 80 #endif /* __cplusplus */ 81 #endif /* P2PLINK_INTERFACE_H */