1 /* 2 * Copyright (c) 2022 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 LNN_LANE_LINK_H 17 #define LNN_LANE_LINK_H 18 19 #include <stdint.h> 20 #include "lnn_lane_def.h" 21 #include "softbus_common.h" 22 #include "softbus_def.h" 23 #include "softbus_protocol_def.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 typedef struct { 30 char peerNetworkId[NETWORK_ID_BUF_LEN]; 31 int32_t pid; 32 bool networkDelegate; 33 LaneTransType transType; 34 LaneLinkType linkType; 35 ProtocolType acceptableProtocols; 36 } LinkRequest; 37 38 typedef struct { 39 int32_t channel; 40 LaneBandwidth bw; 41 WlanConnInfo connInfo; 42 } WlanLinkInfo; 43 44 typedef struct { 45 int32_t channel; 46 LaneBandwidth bw; 47 P2pConnInfo connInfo; 48 } P2pLinkInfo; 49 50 typedef struct { 51 char brMac[BT_MAC_LEN]; 52 } BrLinkInfo; 53 54 // 'GATT' and 'CoC' protocols under BLE use the same definitions 55 typedef struct { 56 BleProtocolType protoType; 57 char bleMac[BT_MAC_LEN]; 58 char deviceIdHash[UDID_HASH_LEN]; 59 int32_t psm; 60 } BleLinkInfo; 61 62 // 'GATT' and 'CoC' protocols under BLE use the same definitions 63 typedef struct { 64 BleProtocolType protoType; 65 int32_t psm; // mark-- 66 char nodeIdHash[NODEID_SHORT_HASH_LEN]; 67 char localUdidHash[UDID_SHORT_HASH_LEN]; 68 char peerUdidHash[SHA_256_HASH_LEN]; 69 } BleDirectInfo; 70 71 typedef struct { 72 LaneLinkType type; 73 union { 74 WlanLinkInfo wlan; 75 P2pLinkInfo p2p; 76 BrLinkInfo br; 77 BleLinkInfo ble; 78 BleDirectInfo bleDirect; 79 } linkInfo; 80 } LaneLinkInfo; 81 82 typedef struct { 83 void (*OnLaneLinkSuccess)(uint32_t reqId, const LaneLinkInfo *linkInfo); 84 void (*OnLaneLinkFail)(uint32_t reqId, int32_t reason); 85 void (*OnLaneLinkException)(uint32_t reqId, int32_t reason); 86 } LaneLinkCb; 87 88 int32_t InitLaneLink(void); 89 void DeinitLaneLink(void); 90 int32_t BuildLink(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *cb); 91 void DestroyLink(const char *networkId, uint32_t reqId, LaneLinkType type, int32_t pid); 92 93 void LaneDeleteP2pAddress(const char *networkId); 94 void LaneAddP2pAddress(const char *networkId, const char *ipAddr, uint16_t port); 95 96 void LaneAddP2pAddressByIp(const char *ipAddr, uint16_t port); 97 void LaneUpdateP2pAddressByIp(const char *ipAddr, const char *networkId); 98 99 #ifdef __cplusplus 100 } 101 #endif 102 #endif /* LNN_LANE_LINK_H */