• 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 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 typedef struct {
25     void (*onConnected)(int32_t requestId, const char *myIp, const char *peerIp);
26     void (*onConnectFailed)(int32_t requestId, int32_t reason);
27 } P2pLinkCb;
28 
29 typedef struct {
30     int32_t requestId;
31     int64_t authId;
32     char peerMac[P2P_MAC_LEN];
33     P2pLinkRole expectedRole;
34     int pid;
35     P2pLinkCb cb;
36 } P2pLinkConnectInfo;
37 
38 typedef struct {
39     int64_t authId;
40     char peerMac[P2P_MAC_LEN];
41     int pid;
42 } P2pLinkDisconnectInfo;
43 
44 typedef struct {
45     void (*onMyRoleChange)(P2pLinkRole myRole);
46     void (*onDevOffline)(const char *peerMac);
47 } P2pLinkPeerDevStateCb;
48 
49 typedef struct {
50     P2pLinkRole peerRole;
51     P2pLinkRole expectedRole;
52     char peerGoMac[P2P_MAC_LEN];
53     char peerMac[P2P_MAC_LEN];
54     bool isBridgeSupported;
55 } RoleIsConflictInfo;
56 
57 int32_t P2pLinkGetRequestId(void);
58 int32_t P2pLinkConnectDevice(const P2pLinkConnectInfo *info);
59 int32_t P2pLinkDisconnectDevice(const P2pLinkDisconnectInfo *info);
60 int32_t P2pLinkInit(void);
61 
62 void P2pLinkRegPeerDevStateChange(const P2pLinkPeerDevStateCb *cb);
63 int32_t P2pLinkGetLocalIp(char *localIp, int32_t localIpLen);
64 
65 int32_t P2pLinkIsRoleConflict(const RoleIsConflictInfo *info);
66 
67 int32_t P2pLinkGetPeerMacByPeerIp(const char *peerIp, char *peerMac, int32_t macLen);
68 int32_t P2pLinkQueryDevIsOnline(const char *peerMac);
69 #endif