• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 SOFTBUS_CONN_GENERAL_CONNECTION_H
17 #define SOFTBUS_CONN_GENERAL_CONNECTION_H
18 
19 #include "softbus_conn_general_negotiation.h"
20 #include "softbus_conn_interface.h"
21 #include "softbus_utils.h"
22 
23 #include "stdint.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 enum GeneralConnState {
29     STATE_CONNECTING,
30     STATE_CONNECTED,
31 };
32 
33 typedef struct {
34     int32_t pid;
35     char name[GENERAL_NAME_LEN];
36     char pkgName[PKG_NAME_SIZE_MAX];
37     char bundleName[BUNDLE_NAME_MAX];
38 } GeneralConnectionParam;
39 
40 typedef struct {
41     ListNode node;
42     GeneralConnectionParam info;
43 } Server;
44 
45 struct GeneralConnection {
46     ListNode node;
47     uint32_t requestId;
48     uint32_t generalId;
49     uint32_t peerGeneralId;
50     uint32_t abilityBitSet;
51     uint32_t underlayerHandle;
52     int32_t objectRc;
53     BleProtocolType protocol;
54     char udid[UDID_BUF_LEN];
55     char networkId[NETWORK_ID_BUF_LEN];
56     char addr[BT_MAC_LEN];
57     bool isSupportNetWorkIdExchange;
58     bool isClient;
59     enum GeneralConnState state;
60     GeneralConnectionParam info;
61     void (*reference)(struct GeneralConnection *self);
62     void (*dereference)(struct GeneralConnection *self);
63     SoftBusMutex lock;
64 };
65 
66 typedef struct {
67     void (*onConnectSuccess)(GeneralConnectionParam *info, uint32_t generalHandle);
68     void (*onConnectFailed)(GeneralConnectionParam *info, uint32_t generalHandle, int32_t reason);
69     void (*onAcceptConnect)(GeneralConnectionParam *info, uint32_t generalHandle);
70     void (*onDataReceived)(GeneralConnectionParam *info, uint32_t generalHandle, const uint8_t *data, uint32_t dataLen);
71     void (*onConnectionDisconnected)(GeneralConnectionParam *info, uint32_t generalHandle, int32_t reason);
72 } GeneralConnectionListener;
73 
74 typedef struct {
75     int32_t (*registerListener)(const GeneralConnectionListener *listener);
76     int32_t (*createServer)(const GeneralConnectionParam *param);
77     void (*closeServer)(const GeneralConnectionParam *param);
78 
79     int32_t (*connect)(const GeneralConnectionParam *param, const char *addr);
80     int32_t (*send)(uint32_t generalHandle, const uint8_t *data, uint32_t dataLen, int32_t pid);
81 
82     void (*disconnect)(uint32_t generalHandle, int32_t pid);
83     int32_t (*getPeerDeviceId)(uint32_t generalHandle, char *addr, uint32_t length,
84         uint32_t tokenId, int32_t pid);
85     void (*cleanupGeneralConnection)(const char *bundleName, int32_t pid);
86 } GeneralConnectionManager;
87 
88 GeneralConnectionManager *GetGeneralConnectionManager(void);
89 int32_t InitGeneralConnectionManager(void);
90 
91 #ifdef __cplusplus
92 }
93 #endif /* __cplusplus */
94 #endif /* SOFTBUS_CONN_GENERAL_CONNECTION_H */