Export to GitHub

btstack - issue #449

Help: understanding the binary representation of a Bluetooth address


Posted on Feb 21, 2015 by Grumpy Rhino

As per the specification ,Bluetooth Device Address as 6 Byte, and Bluetooth device Addresses looks like this "12:45:78:01:34:67". I observed the code,

define BD_ADDR_LEN 6

typedef uint8_t bd_addr_t[BD_ADDR_LEN];

As per the code, it supports only the Device address up to 6 characters. "12:45:" Modified the Code to support complete Bluetooth Device Address of 18 Characters as code given below.

define BD_ADDR_LEN 18

typedef uint8_t bd_addr_t[BD_ADDR_LEN];

Attachments

Comment #1

Posted on Feb 21, 2015 by Swift Ox

The bluetooth address is similar to the MAC addresses. In BTstack, it's binary representation of 6 bytes ist stored in bt_addr_t. If needed, this can be converted to a human readable string.

Comment #2

Posted on Feb 23, 2015 by Grumpy Rhino

How many bytes we require to store this Bluetooth Address("12:45:78:01:34:67")? As per my understanding, uint8_t bd_addr_t[6] buffer capable enough to store the Bluetooth address of 6 bytes that to "12:45.

I didn't understand, how uint8_t bd_addr_t[6] is capable enough to store 18 Bytes of Bluetooth address. if we want to store the Bluetooth address of 18 bytes, we require the buffer of uint8_t bd_addr_t[18].

Comment #3

Posted on Feb 23, 2015 by Swift Ox

A Bluetooth address has exactly 6 bytes of information.

How many bytes do you need to store the value 100? It's one byte and not 3-4 if you look at the string representation "100".

Asides from that: BTstack is working and tested against the official Bluetooth tests. If it couldn't store the Bluetooth address, it wouldn't work at all.

Please stop adding issues on this tracker for questions. Please try to figure out how to find a string in a set of files using either "grep" or the search functionality of a text editor (if it can handle projects).

You may post on the mailing list for help.

Comment #4

Posted on Feb 23, 2015 by Grumpy Rhino

Comment deleted

Comment #5

Posted on Feb 23, 2015 by Grumpy Rhino

Comment deleted

Comment #6

Posted on Feb 23, 2015 by Grumpy Rhino

There is one small index error on comment #5, you can refer comment #6

Code Snippet to support Comment #2 if we want to store string "Hello", we require the msg array of size6.

uint8_t msg[6] = "Hello"; msg[0] = 'H'; msg[1] = 'e'; msg[2] = 'l'; msg[3] = 'l'; msg[4] = 'o'; msg[5] = '\0';

As per the comment #2, uint8_t bd_addr_t[18] = "12:45:78:01:34:67" requires 18 ,as the size of the array to store complete Bluetooth Device Address.

bd_addr_t[0] = '1'; bd_addr_t[1] = '2'; bd_addr_t[2] = ':'; bd_addr_t[3] = '4'; bd_addr_t[4] = '5'; bd_addr_t[5] = ':'; bd_addr_t[6] = '7'; bd_addr_t[7] = '8'; bd_addr_t[8] = ':'; bd_addr_t[9] = '0'; bd_addr_t[10] = '1'; bd_addr_t[11] = ':'; bd_addr_t[12] = '3'; bd_addr_t[13] = '4'; bd_addr_t[14] = ':'; bd_addr_t[15] = '6'; bd_addr_t[16] = '7'; bd_addr_t[17] = ':';

Comment #7

Posted on Feb 23, 2015 by Swift Ox

The example for storing "hello" is correct. it requires 6 bytes with the final \0. Each character is stored as a single byte. However, a byte has 8 bits, and you can have 256 different values in a single byte. The Bluetooth address is given as 6 hex values with ':' in between. The ':' isn't stored.

So, "12:45:78:01:34:67" is stored in memory as { 0x12, 0x45, 0x78, 0x01, 0x34, 0x67 } taking up 6 bytes of memory.

That's not the same as storing the same characters as string, which would take 18 bytes.

Comment #8

Posted on Feb 24, 2015 by Grumpy Rhino

Please confirm the below mentioned C programming statements, From your point of you we understand that these both statements are either similar or same.

uint8_t bd_addr_t[6] = "12:45:78:01:34:67"; uint8_t bd_addr_t[6] = {0x12, 0x45, 0x78, 0x01, 0x34, 0x67 };

Comment #9

Posted on Feb 26, 2015 by Swift Ox

Hi

these statements are different. The first one is also incorrect, it would be uint8_t bd_addr_t[18] = "12:45:78:01:34:67" (as you've used before)

Anyway, this one stores a C string of len 17 in memory. This string is the human readable representation of a 6 byte Bluetooth address.

bd_addr_t (or uint8_t[6]) stores these directly in memory.

... a I see where I might have confused you. BTstack doesn't store "12:45:78:01:34:67" in memory. It stores the 6 byte representation of the same address.

Status: WontFix

Labels:
Type-Patch