1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #pragma once 19 20 #include "tl_common.h" 21 22 /** @defgroup ATT_PERMISSIONS_BITMAPS GAP ATT Attribute Access Permissions Bit Fields 23 * @{ 24 * (See the Core_v5.0(Vol 3/Part C/10.3.1/Table 10.2) for more information) 25 */ 26 #define ATT_PERMISSIONS_AUTHOR 0x10 // Attribute access(Read & Write) requires Authorization 27 #define ATT_PERMISSIONS_ENCRYPT 0x20 // Attribute access(Read & Write) requires Encryption 28 #define ATT_PERMISSIONS_AUTHEN 0x40 // Attribute access(Read & Write) requires Authentication(MITM protection) 29 #define ATT_PERMISSIONS_SECURE_CONN 0x80 // Attribute access(Read & Write) requires Secure_Connection 30 #define ATT_PERMISSIONS_SECURITY \ 31 (ATT_PERMISSIONS_AUTHOR | ATT_PERMISSIONS_ENCRYPT | ATT_PERMISSIONS_AUTHEN | ATT_PERMISSIONS_SECURE_CONN) 32 33 // user can choose permission below 34 #define ATT_PERMISSIONS_READ 0x01 // !< Attribute is Readable 35 #define ATT_PERMISSIONS_WRITE 0x02 // !< Attribute is Writable 36 #define ATT_PERMISSIONS_RDWR (ATT_PERMISSIONS_READ | ATT_PERMISSIONS_WRITE) // !< Attribute is Readable & Writable 37 38 #define ATT_PERMISSIONS_ENCRYPT_READ (ATT_PERMISSIONS_READ | ATT_PERMISSIONS_ENCRYPT) // !< Read requires Encryption 39 #define ATT_PERMISSIONS_ENCRYPT_WRITE \ 40 (ATT_PERMISSIONS_WRITE | ATT_PERMISSIONS_ENCRYPT) // !< Write requires Encryption 41 #define ATT_PERMISSIONS_ENCRYPT_RDWR \ 42 (ATT_PERMISSIONS_RDWR | ATT_PERMISSIONS_ENCRYPT) // !< Read & Write requires Encryption 43 44 #define ATT_PERMISSIONS_AUTHEN_READ \ 45 (ATT_PERMISSIONS_READ | ATT_PERMISSIONS_ENCRYPT | ATT_PERMISSIONS_AUTHEN) // !< Read requires Authentication 46 #define ATT_PERMISSIONS_AUTHEN_WRITE \ 47 (ATT_PERMISSIONS_WRITE | ATT_PERMISSIONS_ENCRYPT | ATT_PERMISSIONS_AUTHEN) // !< Write requires Authentication 48 #define ATT_PERMISSIONS_AUTHEN_RDWR \ 49 (ATT_PERMISSIONS_RDWR | ATT_PERMISSIONS_ENCRYPT | \ 50 ATT_PERMISSIONS_AUTHEN) // !< Read & Write requires Authentication 51 52 #define ATT_PERMISSIONS_SECURE_CONN_READ \ 53 (ATT_PERMISSIONS_READ | ATT_PERMISSIONS_SECURE_CONN | ATT_PERMISSIONS_ENCRYPT | \ 54 ATT_PERMISSIONS_AUTHEN) // !< Read requires Secure_Connection 55 #define ATT_PERMISSIONS_SECURE_CONN_WRITE \ 56 (ATT_PERMISSIONS_WRITE | ATT_PERMISSIONS_SECURE_CONN | ATT_PERMISSIONS_ENCRYPT | \ 57 ATT_PERMISSIONS_AUTHEN) // !< Write requires Secure_Connection 58 #define ATT_PERMISSIONS_SECURE_CONN_RDWR \ 59 (ATT_PERMISSIONS_RDWR | ATT_PERMISSIONS_SECURE_CONN | ATT_PERMISSIONS_ENCRYPT | \ 60 ATT_PERMISSIONS_AUTHEN) // !< Read & Write requires Secure_Connection 61 62 #define ATT_PERMISSIONS_AUTHOR_READ (ATT_PERMISSIONS_READ | ATT_PERMISSIONS_AUTHOR) // !< Read requires Authorization 63 #define ATT_PERMISSIONS_AUTHOR_WRITE \ 64 (ATT_PERMISSIONS_WRITE | ATT_PERMISSIONS_AUTHEN) // !< Write requires Authorization 65 #define ATT_PERMISSIONS_AUTHOR_RDWR \ 66 (ATT_PERMISSIONS_RDWR | ATT_PERMISSIONS_AUTHOR) // !< Read & Write requires Authorization 67 68 /** @} End GAP_ATT_PERMISSIONS_BITMAPS */ 69 70 /** @ add to group GATT_Characteristic_Property GATT characteristic properties 71 * @{ 72 */ 73 #define CHAR_PROP_BROADCAST 0x01 // !< permit broadcasts of the Characteristic Value 74 #define CHAR_PROP_READ 0x02 // !< permit reads of the Characteristic Value 75 #define CHAR_PROP_WRITE_WITHOUT_RSP 0x04 // !< Permit writes of the Characteristic Value without response 76 #define CHAR_PROP_WRITE 0x08 // !< Permit writes of the Characteristic Value with response 77 #define CHAR_PROP_NOTIFY 0x10 // !< Permit notifications of a Characteristic Value without acknowledgement 78 #define CHAR_PROP_INDICATE 0x20 // !< Permit indications of a Characteristic Value with acknowledgement 79 #define CHAR_PROP_AUTHEN 0x40 // !< permit signed writes to the Characteristic Value 80 #define CHAR_PROP_EXTENDED 0x80 // !< additional characteristic properties are defined 81 82 /** @} end of group GATT_Characteristic_Property */ 83 84 typedef int (*att_readwrite_callback_t)(u16 connHandle, void *p); 85 86 typedef struct attribute { 87 u16 attNum; 88 u8 perm; 89 u8 uuidLen; 90 u32 attrLen; // 4 bytes aligned 91 u8 *uuid; 92 u8 *pAttrValue; 93 att_readwrite_callback_t w; 94 att_readwrite_callback_t r; 95 } attribute_t; 96 97 /******************************* User Interface Begin ***************************************************************/ 98 99 /** 100 * @brief Register ATT table. 101 * @param[in] p - Pointer point to attribute table. 102 * @return[in] 0: success 103 * other: fail 104 */ 105 void bls_att_setAttributeTable(u8 *p); 106 107 /** 108 * @brief This function is used to set prepare write buffer 109 * @param[in] *p - the pointer of buffer 110 * @param[in] len - the length of buffer 111 * @return none. 112 */ 113 void blc_att_setPrepareWriteBuffer(u8 *p, u16 len); 114 115 /** 116 * @brief This function is used to set MTU req pending timing after connection created 117 * @param[in] time_ms - pending timing, unit: ms 118 * @return none 119 */ 120 void blc_att_setMtureqSendingTime_after_connCreate(int time_ms); 121 /** 122 * @brief This function is used to set RX MTU size in master 123 * @param[in] master_mtu_size - ATT MTU size 124 * @return[in] 0: success 125 * other: fail 126 */ 127 ble_sts_t blc_att_setMasterRxMTUSize(u16 master_mtu_size); 128 129 /** 130 * @brief This function is used to set RX MTU size in slave 131 * @param[in] slave_mtu_size - ATT MTU size 132 * @return[in] 0: success 133 * other: fail 134 */ 135 ble_sts_t blc_att_setSlaveRxMTUSize(u16 slave_mtu_size); 136 137 /** 138 * @brief Send MTU Size Exchange Request. 139 * @param[in] mtu_size - ATT MTU size 140 * @return[in] 0: success 141 * other: fail 142 */ 143 ble_sts_t blc_att_requestMtuSizeExchange(u16 connHandle, u16 mtu_size); 144 145 /******************************* User Interface End ****************************************************************/ 146