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