diff --git a/include/btstack/utils.h b/include/btstack/utils.h index 5c84dbe63..fbf64c29c 100644 --- a/include/btstack/utils.h +++ b/include/btstack/utils.h @@ -63,6 +63,10 @@ typedef uint8_t link_key_t[LINK_KEY_LEN]; #define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16)) #define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24) +// helper for SDP big endian format +#define READ_NET_16( buffer, pos) ( ((uint16_t) buffer[pos+1]) | (((uint16_t)buffer[pos ]) << 8)) +#define READ_NET_32( buffer, pos) ( ((uint32_t) buffer[pos+3]) | (((uint32_t)buffer[pos+2]) << 8) | (((uint32_t)buffer[pos+1]) << 16) | (((uint32_t) buffer[pos])) << 24) + // HCI CMD OGF/OCF #define READ_CMD_OGF(buffer) (buffer[1] >> 2) #define READ_CMD_OCF(buffer) ((buffer[1] & 0x03) << 8 | buffer[0]) @@ -79,17 +83,13 @@ typedef uint8_t link_key_t[LINK_KEY_LEN]; #define READ_L2CAP_LENGTH(buffer) ( READ_BT_16(buffer, 4)) #define READ_L2CAP_CHANNEL_ID(buffer) ( READ_BT_16(buffer, 6)) -// L2CAP Signaling Packet -#define READ_L2CAP_SIGNALING_CODE( buffer ) (buffer[ 8]) -#define READ_L2CAP_SIGNALING_IDENTIFIER( buffer ) (buffer[ 9]) -#define READ_L2CAP_SIGNALING_LENGTH( buffer ) (READ_BT_16(buffer, 10)) - -#define L2CAP_SIGNALING_DATA_OFFSET 12 - void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value); void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); void bt_flip_addr(bd_addr_t dest, bd_addr_t src); +void net_store_16(uint8_t *buffer, uint16_t pos, uint16_t value); +void net_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); + void hexdump(void *data, int size); void print_bd_addr(bd_addr_t addr); int sscan_bd_addr(uint8_t * addr_string, bd_addr_t addr); diff --git a/src/utils.c b/src/utils.c index e961446a8..97d86469f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -53,6 +53,18 @@ void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){ buffer[pos++] = value >> 24; } +void net_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){ + buffer[pos++] = value >> 8; + buffer[pos++] = value; +} + +void net_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){ + buffer[pos++] = value >> 24; + buffer[pos++] = value >> 16; + buffer[pos++] = value >> 8; + buffer[pos++] = value; +} + void bt_flip_addr(bd_addr_t dest, bd_addr_t src){ dest[0] = src[5]; dest[1] = src[4];