蓝牙LMP剖析(二)

这篇博客主要介绍了蓝牙LMP(Link Management Protocol)的相关内容,包括 bt_lmp.h 和 bt_lmp.c 的源码分析。
摘要由CSDN通过智能技术生成

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

以下是 bt_lmp.h 源码:

/** This file is part of the LMP protocal.* Data  :20160423* Author: zhongjun**/#ifndef BT_LMP_H_H#define BT_LMP_H_H#include "bt_cfg.h"#ifdef DEBUG_BT_LMP#define DEBUG(x) {printf x;}#define BT_LMP_DEBUG(x) DEBUG(x)#else#define BT_LMP_DEBUG(x) #endif/*HDR INDEX*/#define CMD_F_POS 0#define CMD_S_POS 1/*HDR SIZE*/#define PDU_S_LENGTH 1#define PDU_B_LENGTH 2/*HDR DETAIL*/#define CMD_TID_MASK 0x01#define CMD_OPC_S_MASK 0xFE/*FEATURE MASK*///0 index byte 0-7bit#define three_slot_packets_mask 0x1#define five_slot_packets_mask  0x2#define Encryption_mask 0x4#define Slot_offset_mask 0x8#define Timing_accuracy_mask 0x10#define Hold_mode_mask 0x40#define Sniff_mode_mask 0x80//1 index byte 0-7bit#define Park_state_mask 0x100#define Power_control_requests_mask  0x200#define CQDDR_mask 0x400#define SCO_link_mask 0x800#define HV2_packets_mask 0x1000#define HV3_packets_mask 0x2000#define u_law_log_synchronous_data_mask 0x4000#define A_law_log_synchronous_data_mask 0x8000//2 index byte 0-7bit#define CVSD_synchronous_data_mask 0x10000#define Paging_parameter_negotiation_mask  0x20000#define Power_control_mask 0x40000#define Transparent_synchronous_data_mask 0x80000#define Flow_control_least_lag_mask 0x100000#define Flow_control_middle_lag_mask 0x200000#define Flow_control_most_lag_mask 0x400000#define Broadcast_Encryption_mask 0x800000//3 index byte 0-7bit#define Reserved_3_0_mask 0x1000000#define EDR_ACL_2_M_mask  0x2000000#define EDR_ACL_3_M_mask 0x4000000#define Enhanced_inquiry_scan_mask 0x8000000#define Interlaced_inquiry_scan_mask 0x10000000#define Interlaced_page_scan_mask 0x20000000#define RSSI_with_inquiry_results_mask 0x40000000#define Extended_SCO_link_EV3_mask 0x80000000//4 index byte 0-7bit#define EV4_packets_mask 0x100000000#define EV5_packets_mask  0x200000000#define Reserved_4_2_mask 0x400000000#define AFH_capable_slave_mask 0x800000000#define AFH_classification_slave_mask  0x1000000000#define BR_EDR_Not_Supported_mask 0x2000000000#define LE_Supported_mask 0x4000000000#define three_slot_EDR_ACL_mask 0x8000000000//5 index byte 0-7bit#define five_slot_EDR_ACL_mask 0x10000000000#define Sniff_subrating_mask  0x20000000000#define Pause_encryption_mask 0x40000000000#define AFH_capable_master_mask 0x80000000000#define AFH_classification_master_mask  0x100000000000#define EDR_eSCO_2_M_mask 0x200000000000#define EDR_eSCO_3_M_mask 0x400000000000#define three_slot_EDR_eSCO_mask 0x800000000000//6 index byte 0-7bit#define Extended_Inquiry_Response_mask 0x1000000000000#define Simultaneous_LE_and_BR_EDR_to_Same_Device_Capable_mask  0x2000000000000#define Reserved_6_2_mask 0x4000000000000#define Secure_Simple_Pairing_mask 0x8000000000000#define Encapsulated_PDU_mask  0x10000000000000#define Erroneous_Data_Reporting_mask 0x20000000000000#define Non_flushable_Packet_Boundary_Flag_mask 0x40000000000000#define Reserved_6_7_mask 0x80000000000000//7 index byte 0-7bit#define Link_Supervision_Timeout_Changed_Event_mask 0x1000000000000#define Inquiry_TX_Power_Level_mask  0x2000000000000#define Enhanced_Power_Control_mask 0x4000000000000#define Reserved_7_3_mask 0x8000000000000#define Reserved_7_4_mask  0x10000000000000#define Reserved_7_5_mask 0x20000000000000#define Reserved_7_6_mask 0x40000000000000#define Extended_features_mask 0x80000000000000//FEATURE SUPPORT#define LMP_FEATURE_SUPPORT(src_feature,des_feature) ((src_feature & des_feature) == des_feature)/* PDU HDR PARSE*/#define LMP_GET_TID(buf)          (((uint8_t *)buf)[CMD_F_POS] & CMD_TID_MASK)#define LMP_GET_S_OPC(buf)          ((((uint8_t *)buf)[CMD_F_POS] & CMD_OPC_S_MASK) >> 1)#define LMP_SET_S_HDR(buf,role,opc) (((uint8_t *)buf)[CMD_F_POS]  = ((opc << 1) | role)) /*PDU HDR SIZE*/typedef uint8_t LMP_PDU_HDR_S;typedef uint8_t LMP_PDU_HDR_B[2];/*ROLE*/typedef enum {  LMP_MASTER_ROLE = 0,  LMP_SLAVE_ROLE = 1,}LMP_ROLE;/* ACCEPT RESULT*/typedef enum {  LMP_ACCEPT = 0,  LMP_NOT_ACCEPT = 1,}LMP_ACCEPT_RESULT;/*VERSION DEFINE*/typedef enum{  LMP_VERSION_4_0 = 0x6,  LMP_RESERVED = 0x7,}LMP_VERSION_DEF;typedef enum{  BROADCOM = 0xF000,  TI = 0xD000,}LMP_COM_ID_DEF;typedef enum{  LMP_SBUVERSION = 0x0,}LMP_SUBVERSION_DEF;/*PDU ID*/typedef enum {  LMP_name_req = 1,  LMP_name_rsp = 2,  LMP_accepted = 3,  LMP_not_accepted = 4,  LMP_clkoffset_req = 5,  LMP_clkoffset_rsp = 6,  LMP_detach = 7,  LMP_in_rand = 8,  LMP_comb_key = 9,  LMP_au_rand = 11,  LMP_sres = 12,  LMP_switch_req = 19,  LMP_hold = 20,  LMP_hold_req = 21,  LMP_sniff_req = 23,  LMP_park_req = 25,  LMP_incr_power_req = 31,  LMP_decr_power_req = 32,  LMP_max_power = 33,  LMP_min_power = 34,  LMP_auto_rate = 35,  LMP_preferred_rate = 36,  LMP_version_req = 37,  LMP_version_rsp = 38,  LMP_features_req = 39,  LMP_features_rsp = 40,    LMP_quality_of_service = 41,  LMP_quality_of_service_req = 42,  LMP_SCO_link_req = 43,  LMP_remove_SCO_link_req = 44,  LMP_max_slot = 45,  LMP_max_slot_req = 46,  LMP_setup_complete = 49,  LMP_host_connection_req = 51,  LMP_slot_offset = 52,  LMP_page_mode_req = 53,  LMP_page_scan_mode_req = 54,  LMP_supervision_timeout = 55,  LMP_set_AFH = 60,  LMP_Simple_Pairing_Confirm = 63,  LMP_Simple_Pairing_Number = 64,}LMP_OPCODE_ID_S;/*DETAIL PDU FORMAT*/#pragma pack (1)typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t name_offset;}LMP_name_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t name_offset;  uint8_t name_length;  uint8_t name[14];}LMP_name_rsp_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint64_t feature;}LMP_features_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint64_t feature;}LMP_features_rsp_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_host_connection_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t opcode;}LMP_accepted_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t opcode;  uint8_t errcode;}LMP_not_accepted_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t versnr;  uint16_t compid;  uint16_t subvernr;}LMP_version_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t versnr;  uint16_t compid;  uint16_t subvernr;}LMP_version_rsp_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint32_t AFH_instant;  uint8_t AFH_mode;  uint8_t AFH_channel_map[10];}LMP_set_AFH_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_setup_complete_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t random_nub[16];}LMP_in_rand_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t random_nub[16];}LMP_comb_key_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t random_nub[16];}LMP_au_rand_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t auth_rsp[4];}LMP_sres_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_auto_rate_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_clkoffset_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint16_t clock_offset;}LMP_clkoffset_rsp_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t reserved;}LMP_incr_power_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t reserved;}LMP_decr_power_req_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_max_power_format;typedef struct{
      LMP_PDU_HDR_S hdr;}LMP_min_power_format;typedef struct{
      LMP_PDU_HDR_S hdr;  uint8_t errcode;}LMP_detach_format;typedef struct{
    </
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值