| /****************************************************************************** |
| * @file ble_format.h |
| * |
| * @brief for TLSR chips |
| * |
| * @author public@telink-semi.com; |
| * @date Sep. 30, 2010 |
| * |
| * @attention |
| * |
| * Copyright (C) 2019-2020 Telink Semiconductor (Shanghai) Co., Ltd. |
| * Copyright (C) Atmosic 2022 |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| *****************************************************************************/ |
| #ifndef BLE_FORMAT_H |
| #define BLE_FORMAT_H |
| |
| |
| |
| #include "stack/ble/ble_common.h" |
| |
| /******************************************** Link Layer **************************************************************/ |
| |
| typedef struct { |
| u8 type; |
| u8 address[6];//BLE_ADDR_LEN]; |
| } addr_t; |
| |
| |
| |
| typedef struct { |
| u8 llid :2; |
| u8 nesn :1; |
| u8 sn :1; |
| u8 md :1; |
| u8 rfu1 :3; |
| }rf_data_head_t; |
| |
| |
| |
| typedef struct { |
| u8 llid :2; |
| u8 nesn :1; |
| u8 sn :1; |
| u8 md :1; |
| u8 rfu1 :3; |
| u8 rf_len; |
| }rf_acl_data_head_t; |
| |
| |
| |
| typedef struct { |
| u8 llid :2; |
| u8 nesn :1; |
| u8 sn :1; |
| u8 cie :1; |
| u8 rfu0 :1; |
| u8 npi :1; |
| u8 rfu1 :1; |
| u8 rf_len; |
| }rf_cis_data_hdr_t; |
| |
| |
| |
| typedef struct { |
| u8 llid :2; |
| u8 cssn :3; |
| u8 cstf :1; |
| u8 rfu0 :2; |
| u8 rf_len; |
| }rf_bis_data_hdr_t; |
| |
| |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; //LEN(6)_RFU(2) |
| |
| u8 advA[6]; //address |
| u8 data[31]; |
| }rf_packet_adv_t; |
| |
| |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; //LEN(6)_RFU(2) |
| |
| u8 scanA[6]; // |
| u8 advA[6]; // |
| }rf_packet_scan_req_t; |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; //LEN(6)_RFU(2) |
| |
| u8 advA[6]; //address |
| u8 data[31]; //0-31 byte |
| }rf_packet_scan_rsp_t; |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; //LEN(6)_RFU(2) |
| u8 initA[6]; //scanA |
| u8 advA[6]; // |
| u8 accessCode[4]; // access code |
| u8 crcinit[3]; |
| u8 winSize; |
| u16 winOffset; |
| u16 interval; |
| u16 latency; |
| u16 timeout; |
| u8 chm[5]; |
| u8 hop; //sca(3)_hop(5) |
| }rf_packet_connect_t; |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; //LEN(6)_RFU(2) |
| u8 scanA[6]; // |
| u8 advA[6]; // |
| u8 aa[4]; // access code |
| u8 crcinit[3]; |
| u8 wsize; |
| u16 woffset; |
| u16 interval; |
| u16 latency; |
| u16 timeout; |
| u8 chm[5]; |
| u8 hop; //sca(3)_hop(5) |
| }rf_packet_ll_init_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 winSize; |
| u16 winOffset; |
| u16 interval; |
| u16 latency; |
| u16 timeout; |
| u16 instant; |
| } rf_packet_ll_updateConnPara_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 winSize; |
| u16 winOffset; |
| u16 interval; |
| u16 latency; |
| u16 timeout; |
| u16 instant; |
| }rf_packet_connect_upd_req_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 chm[5]; |
| u16 instant; |
| } rf_packet_chm_upd_req_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 rand[8]; |
| u16 ediv; |
| u8 skdm[8]; |
| u8 ivm[4]; |
| } rf_packet_ll_enc_req_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 skds[8]; |
| u8 ivs[4]; |
| } rf_packet_ll_enc_rsp_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 unknownType; |
| } rf_packet_ll_unknown_rsp_t; |
| |
| typedef struct { |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 featureSet[8]; |
| } rf_packet_ll_feature_exg_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 versNr; |
| u16 compId; |
| u16 subVersNr; |
| }rf_packet_version_ind_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 errCode; |
| }rf_packet_ll_reject_ind_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 rejectOpcode; |
| u8 errCode; |
| }rf_packet_ll_reject_ext_ind_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 reason; |
| }rf_packet_ll_terminate_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 cigId; |
| u8 cisId; |
| u8 phyM2S; |
| u8 phyS2M; |
| |
| u32 maxSduM2S :12; |
| u32 rfu0 :3; |
| u32 framed :1; |
| u32 maxSduS2M :12; |
| u32 rfu1 :4; |
| |
| u8 sduIntvlM2S[3]; //SDU_Interval_M_To_S(20 bits) + RFU(4 bits) |
| u8 sduIntvlS2M[3]; //SDU_Interval_S_To_M(20 bits) + RFU(4 bits) |
| |
| u16 maxPduM2S; |
| u16 maxPduS2M; |
| u8 nse; |
| u8 subIntvl[3]; //unit: uS |
| |
| u8 bnM2S:4; |
| u8 bnS2M:4; |
| u8 ftM2S; |
| u8 ftS2M; |
| u16 isoIntvl; //unit: 1.25 mS |
| |
| u8 cisOffsetMin[3]; |
| u8 cisOffsetMax[3]; |
| u16 connEventCnt; //similar to instant |
| |
| }rf_packet_ll_cis_req_t; |
| |
| typedef struct{ |
| u8 type; //RA(1)_TA(1)_RFU(2)_TYPE(4) |
| u8 rf_len; //LEN(6)_RFU(2) |
| u8 opcode; |
| u8 cisOffsetMin[3]; |
| u8 cisOffsetMax[3]; |
| u16 connEventCnt; |
| }rf_packet_ll_cis_rsp_t; |
| |
| typedef struct{ |
| u8 type; //RA(1)_TA(1)_RFU(2)_TYPE(4) |
| u8 rf_len; //LEN(6)_RFU(2) |
| u8 opcode; |
| u32 cisAccessAddr; //Access Address of the CIS |
| u8 cisOffset[3]; |
| u8 cigSyncDly[3]; |
| u8 cisSyncDly[3]; |
| u16 connEventCnt; |
| }rf_packet_ll_cis_ind_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u8 opcode; |
| u8 cig_id; |
| u8 cis_id; |
| u8 errorCode; |
| }rf_packet_ll_cis_terminate_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| |
| u8 opcode; // |
| u8 dat[1]; // |
| }rf_packet_ll_control_t; |
| |
| typedef struct{ |
| union{ |
| rf_bis_data_hdr_t bisPduHdr; |
| rf_cis_data_hdr_t cisPduHdr; |
| rf_acl_data_head_t aclPduHdr; |
| struct{ |
| u8 type; |
| u8 rf_len; |
| }pduHdr; |
| }llPduHdr; /* LL PDU Header: 2 */ |
| u8 llPayload[1]; /* Max LL Payload length: 251 */ |
| }llPhysChnPdu_t; |
| |
| typedef struct{ |
| u32 dma_len; |
| llPhysChnPdu_t llPhysChnPdu; |
| }rf_packet_ll_data_t; |
| |
| |
| |
| |
| //AuxPrt |
| typedef struct{ |
| u8 chn_index :6; |
| u8 ca :1; |
| u8 offset_unit :1; |
| u16 aux_offset :13; |
| u16 aux_phy :3; |
| } aux_ptr_t; |
| |
| |
| typedef struct{ |
| u32 dma_len; |
| |
| u8 type :4; |
| u8 rfu1 :1; |
| u8 chan_sel:1; |
| u8 txAddr :1; |
| u8 rxAddr :1; |
| |
| u8 rf_len; |
| u8 ext_hdr_len :6; |
| u8 adv_mode :2; |
| u8 ext_hdr_flg; |
| |
| u8 data[253]; //Extended Header + AdvData |
| }rf_pkt_ext_adv_t; |
| |
| |
| /******************************************** L2CAP **************************************************************/ |
| |
| typedef struct{ |
| rf_data_head_t header; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 data[1]; |
| }rf_packet_l2cap_t; |
| |
| #if !defined(CFG_ATM_SDK) && (MCU_CORE_TYPE == MCU_CORE_9518) |
| typedef struct{ |
| rf_data_head_t header; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u16 handle; |
| u8 dat[20]; |
| }rf_packet_att_t; |
| #elif defined(CFG_ATM_SDK) || (MCU_CORE_TYPE == MCU_CORE_825x || MCU_CORE_TYPE == MCU_CORE_827x) |
| typedef struct{ |
| rf_data_head_t header; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle0; |
| u8 handle1; |
| u8 dat[20]; |
| }rf_packet_att_t; |
| #endif |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 data[1]; |
| }rf_packet_l2cap_req_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 code; |
| u8 id; |
| u16 dataLen; |
| u16 result; |
| }rf_pkt_l2cap_sig_connParaUpRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 code; |
| u8 id; |
| u16 length; |
| u16 psm; |
| u16 mtu; |
| u16 mps; |
| u16 init_credits; |
| u16 scid[5]; |
| }rf_pkt_l2cap_credit_based_connection_req_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 code; |
| u8 id; |
| u16 length; |
| u16 mtu; |
| u16 mps; |
| u16 init_credits; |
| u16 result; |
| u16 dcid[5]; |
| }rf_pkt_l2cap_credit_based_connection_rsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 code; |
| u8 id; |
| u16 length; |
| u16 mtu; |
| u16 mps; |
| u16 dcid[5]; |
| }rf_pkt_l2cap_credit_based_reconfigure_req_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 code; |
| u8 id; |
| u16 length; |
| u16 result; |
| }rf_pkt_l2cap_credit_based_reconfigure_rsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 data[1]; |
| }rf_pkt_l2cap_req_t; |
| |
| typedef struct{ |
| u8 llid; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 id; |
| u16 data_len; |
| u16 min_interval; |
| u16 max_interval; |
| u16 latency; |
| u16 timeout; |
| }rf_packet_l2cap_connParaUpReq_t; |
| |
| typedef struct{ |
| u8 llid; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 id; |
| u16 length; |
| u16 spsm; |
| u16 mtu; |
| u16 mps; |
| u16 init_credits; |
| u16 scid[5]; |
| }rf_packet_l2cap_credit_based_connection_req_t; |
| |
| typedef struct{ |
| u8 llid; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 id; |
| u16 data_len; |
| u16 result; |
| }rf_packet_l2cap_connParaUpRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2cap; |
| u16 chanid; |
| |
| u8 att; |
| u16 handle; |
| |
| #ifdef CFG_ATM_SDK |
| u8 dat[256]; |
| #else |
| u8 dat[20]; |
| #endif |
| |
| }rf_packet_att_data_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 errOpcode; |
| u16 errHandle; |
| u8 errReason; |
| }rf_packet_att_errRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 startingHandle; |
| u8 startingHandle1; |
| u8 endingHandle; |
| u8 endingHandle1; |
| u8 attType[2]; // |
| }rf_packet_att_readByType_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 startingHandle; |
| u8 startingHandle1; |
| u8 endingHandle; |
| u8 endingHandle1; |
| u8 attType[2]; |
| u8 attValue[2]; |
| }rf_packet_att_findByTypeReq_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u16 data[1]; |
| }rf_packet_att_findByTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle; |
| u8 handle1; |
| }rf_packet_att_read_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle; |
| u8 handle1; |
| u8 offset0; |
| u8 offset1; |
| }rf_packet_att_readBlob_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 value[22]; |
| }rf_packet_att_readRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 datalen; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }rf_pkt_att_readByTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 datalen; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }rf_packet_att_readByTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 datalen; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }rf_packet_att_data_readByTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 datalen; |
| u8 data[3]; |
| }rf_packet_att_readByGroupTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 format; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }rf_packet_att_findInfoReq_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 flags; |
| }rf_packet_att_executeWriteReq_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle; |
| u8 handle1; |
| u8 value; |
| }rf_packet_att_write_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle[2]; |
| u8 data; |
| }rf_packet_att_notification_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 mtu[2]; |
| }rf_packet_att_mtu_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 mtu[2]; |
| }rf_packet_att_mtu_exchange_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| }rf_packet_att_writeRsp_t; |
| |
| typedef struct{ |
| u8 type; //RA(1)_TA(1)_RFU(2)_TYPE(4) |
| u8 rf_len; //LEN(6)_RFU(2) |
| u8 opcode; |
| u8 data[8]; |
| }rf_packet_feature_rsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 datalen; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }att_readByTypeRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 format; |
| u8 data[1]; // character_handle / property / value_handle / value |
| }att_findInfoRsp_t; |
| |
| typedef struct{ |
| u8 type; |
| u8 rf_len; |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 value[22]; |
| }att_readRsp_t; |
| |
| typedef struct{ |
| u8 type; //RFU(3)_MD(1)_SN(1)_NESN(1)-LLID(2) |
| u8 rf_len; //LEN(5)_RFU(3) |
| u16 l2capLen; |
| u16 chanId; |
| u8 opcode; |
| u8 handle; |
| u8 hh; |
| u8 value[1]; |
| }att_notify_t; |
| |
| typedef struct { |
| u8 num; |
| u8 property; |
| u16 handle; |
| u16 uuid; |
| u16 ref; |
| } att_db_uuid16_t; //8-byte |
| |
| |
| typedef struct { |
| u8 num; |
| u8 property; |
| u16 handle; |
| u8 uuid[16]; |
| } att_db_uuid128_t; //20-byte |
| #endif /* BLE_FORMAT_H */ |