• 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 SOCKET_DEF_H
17 #define SOCKET_DEF_H
18 
19 #include <stdint.h>
20 
21 namespace bluetooth {
22 // Socket default MTU.
23 static const int SOCK_DEF_RFC_MTU = 1500;
24 // Maximum number of socket service.
25 static const int SOCK_MAX_SERVICE_ID = 36;
26 // Invalid Socket fd.
27 static const int SOCK_INVALID_FD = -1;
28 // Maximum number of clients that can be connected.
29 static const int SOCK_MAX_CLIENT = 6;
30 // Require the connection to be encrypted.
31 static const int SOCK_FLAG_ENCRYPTION = 1;
32 // Require the connection to be authenticated.
33 static const int SOCK_FLAG_AUTHENTICATION = 1 << 1;
34 // Maximum number of socket server.
35 static const int SOCK_MAX_SERVER = 30;
36 
37 // Transport event declarations
38 // The event is triggered when connection failed.
39 static const int RFCOMM_CONNECT_FAIL = 0x0001;
40 // The event is triggered when the disconnection process is successful.
41 static const int RFCOMM_DISCONNECT_SUCCESS = 0x0002;
42 // The event is triggered when the disconnection process fails.
43 static const int RFCOMM_DISCONNECT_FAIL = 0x0003;
44 // The event is triggered when peer or RFCOMM is available to receive data.
45 static const int RFCOMM_EV_FC_ON = 0x0004;
46 
47 // SPP default UUID.
48 static constexpr uint16_t UUID_SERVCLASS_SERIAL_PORT = 0X1101;
49 // SPP version.
50 static const int SPP_PROFILE_VERSION = 0x0102;
51 
52 /**
53  * @brief Socket type.
54  */
55 enum SocketType {
56     SOCK_RFCOMM,   // RFCOMM socket
57     SOCK_L2CAP,    // L2CAP socket
58     SOCK_L2CAP_LE  // L2CAP_LE socket
59 };
60 
61 /**
62  * @brief Socket state.
63  */
64 enum SocketState { INIT, LISTEN, CONNECTING, CONNECTED, DISCONNECTED, CLOSED };
65 
66 /**
67  * @brief Socket event.
68  */
69 enum {
70     SOCKET_SDP_DISCOVERY_RESULT,  // client SDP search completed.
71     SOCKET_CLOSE,                 // close socket.
72     SOCKET_ACCEPT_NEW,            // server accept a connection.
73     SOCKET_CLOSE_COMPLETE,
74 };
75 
76 /**
77  * @brief Socket sdp index.
78  */
79 enum { SOCK_SDP_IDX0 = 0, SOCK_SDP_IDX1 = 1, SOCK_SDP_IDX2 = 2 };
80 
81 /**
82  * @brief Service sends messages to app through socket.
83  */
84 typedef struct {
85     bool status;      // connect state
86     uint8_t addr[6];  // remote device address
87 } SocketConnectInfo;
88 }  // namespace bluetooth
89 
90 #endif // SOCKET_DEF_H