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 BT_RFCOM_H 17 #define BT_RFCOM_H 18 19 #include "ohos_types.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define BT_ADDR_LEN 6 26 #define BT_UUID_LEN 16 27 #define BT_RFCOM_NAME_MAX_LEN 31 28 #define BT_RFCOM_CLIENT_INVALID_HANDLE 0xFF 29 30 typedef uint8 BT_UUID[BT_UUID_LEN]; 31 typedef uint8 BD_ADDR[BT_ADDR_LEN]; 32 33 typedef enum { 34 BT_RFCOM_EVENT_READ = 0x00, /* not used */ 35 BT_RFCOM_EVENT_ACCEPT, 36 BT_RFCOM_EVENT_DISCONNECT, 37 BT_RFCOM_EVENT_CONNECT, 38 BT_RFCOM_EVENT_CONGEST, 39 } BtRfcomEventType; 40 41 typedef struct { 42 /* event type BtRfcomEventType */ 43 void (*OnEvent)(uint8 type, uint8 handle, int value); 44 void (*OnDataReceived)(uint8 handle, const uint8 *buf, uint16 len); 45 } BtRfcomEventCallback; 46 47 typedef enum { 48 BT_RFCOM_STATUS_OK, 49 BT_RFCOM_STATUS_INVALID_HANDLE, 50 BT_RFCOM_STATUS_UNUSED_HANDLE, 51 BT_RFCOM_STATUS_INVALID_PARAM, 52 } BtRfcomStatus; 53 54 /* 55 * return handle, BT_RFCOM_CLIENT_INVALID_HANDLE is invalid 56 */ 57 uint8 BtRfcomClientCreate(const BD_ADDR mac, const BT_UUID uuid); 58 /* 59 * BT_RFCOM_STATUS_OK means success, otherwise fail 60 */ 61 uint8 BtRfcomClientConnect(uint8 handle, BtRfcomEventCallback *cb); 62 /* 63 * BT_RFCOM_STATUS_OK means success, otherwise fail 64 */ 65 uint8 BtRfcomClientDisconnect(uint8 handle); 66 /* 67 * BT_RFCOM_STATUS_OK means success, otherwise fail 68 */ 69 uint8 BtRfcomClientWrite(uint8 handle, uint8 *data, uint16 dataLen); 70 /* 71 * BT_RFCOM_STATUS_OK means success, otherwise fail 72 */ 73 uint8 BtRfcomServerAccept(uint8 handle, BtRfcomEventCallback *cb); 74 /* 75 * return handle, BT_RFCOM_CLIENT_INVALID_HANDLE is invalid 76 */ 77 uint8 BtRfcomServerCreate(const char *name, const BT_UUID uuid); 78 79 void BtRfcomHandleResponse(const uint8 *data, uint16 dataLen); 80 81 #ifdef __cplusplus 82 } 83 #endif 84 #endif /* BT_RFCOM_H */ 85