115 lines
3.9 KiB
Diff
115 lines
3.9 KiB
Diff
From: Anantha Krishnan <ananthk@codeaurora.org>
|
|
Date: Mon, 8 Sep 2014 15:11:02 +0530
|
|
Subject: [PATCH] bluetooth: Configure BD Address
|
|
|
|
Read the BD Address programmed by user from persist location.
|
|
If there is no user programmed BD address then use the default
|
|
BD address present in the firmware file.
|
|
|
|
Change-Id: Id702d1476bae765dfd23f88542bfd5a8a1f26056
|
|
Signed-off-by: Rupesh Tatiya <rtatiya@codeaurora.org>
|
|
---
|
|
tools/hciattach_rome.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---
|
|
tools/hciattach_rome.h | 7 +++++++
|
|
2 files changed, 60 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/tools/hciattach_rome.c b/tools/hciattach_rome.c
|
|
index 122a0f4b89bc..947e1abb96c4 100644
|
|
--- a/tools/hciattach_rome.c
|
|
+++ b/tools/hciattach_rome.c
|
|
@@ -809,6 +809,7 @@ int rome_get_tlv_file(char *file_path)
|
|
tlv_nvm_hdr *nvm_ptr;
|
|
unsigned char data_buf[PRINT_BUF_SIZE]={0,};
|
|
unsigned char *nvm_byte_ptr;
|
|
+ unsigned char bdaddr[6];
|
|
|
|
fprintf(stderr, "File Open (%s)\n", file_path);
|
|
pFile = fopen ( file_path , "r" );
|
|
@@ -886,9 +887,10 @@ int rome_get_tlv_file(char *file_path)
|
|
nvm_byte_ptr+=sizeof(tlv_nvm_hdr);
|
|
|
|
/* Write BD Address */
|
|
- if(nvm_ptr->tag_id == TAG_NUM_2){
|
|
- memcpy(nvm_byte_ptr, vnd_local_bd_addr, 6);
|
|
- fprintf(stderr, "BD Address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x\n",
|
|
+ if(nvm_ptr->tag_id == TAG_NUM_2 && read_bd_address(&bdaddr) == 0) {
|
|
+ memcpy(nvm_byte_ptr, bdaddr, 6);
|
|
+ fprintf(stderr, "Overriding default BD ADDR with user"
|
|
+ " programmed BD Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
*nvm_byte_ptr, *(nvm_byte_ptr+1), *(nvm_byte_ptr+2),
|
|
*(nvm_byte_ptr+3), *(nvm_byte_ptr+4), *(nvm_byte_ptr+5));
|
|
}
|
|
@@ -1451,6 +1453,54 @@ error:
|
|
|
|
}
|
|
|
|
+int read_bd_address(unsigned char *bdaddr)
|
|
+{
|
|
+ int fd = -1;
|
|
+ int readPtr = 0;
|
|
+ unsigned char data[BD_ADDR_LEN];
|
|
+
|
|
+ /* Open the persist file for reading device address*/
|
|
+ fd = open("/etc/bluetooth/.bt_nv.bin", O_RDONLY);
|
|
+ if(fd < 0)
|
|
+ {
|
|
+ fprintf(stderr, "%s: Open failed: Programming default BD ADDR\n", __func__);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* Read the NVM Header : fp will be advanced by readPtr number of bytes */
|
|
+ readPtr = read(fd, data, PERSIST_HEADER_LEN);
|
|
+ if (readPtr > 0)
|
|
+ fprintf(stderr, "%s: Persist header data: %02x \t %02x \t %02x\n", __func__,
|
|
+ data[NVITEM], data[RDWR_PROT], data[NVITEM_SIZE]);
|
|
+ else {
|
|
+ fprintf(stderr, "%s: Read from persist memory failed : Programming default"
|
|
+ " BD ADDR\n");
|
|
+ close(fd);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* Check for BD ADDR length before programming */
|
|
+ if(data[NVITEM_SIZE] != BD_ADDR_LEN) {
|
|
+ fprintf(stderr, "Invalid BD ADDR: Programming default BD ADDR!\n");
|
|
+ close(fd);
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* Read the BD ADDR info */
|
|
+ readPtr = read(fd, data, BD_ADDR_LEN);
|
|
+ if (readPtr > 0)
|
|
+ fprintf(stderr, "BD-ADDR: ==> %02x:%02x:%02x:%02x:%02x:%02x\n", data[0],
|
|
+ data[1], data[2], data[3], data[4], data[5]);
|
|
+ else {
|
|
+ fprintf(stderr, "%s: Read from persist memory failed : Programming default"
|
|
+ " BD ADDR\n");
|
|
+ close(fd);
|
|
+ return -1;
|
|
+ }
|
|
+ memcpy(bdaddr, data, BD_ADDR_LEN);
|
|
+ close(fd);
|
|
+ return 0;
|
|
+}
|
|
|
|
int qca_soc_init(int fd, char *bdaddr)
|
|
{
|
|
diff --git a/tools/hciattach_rome.h b/tools/hciattach_rome.h
|
|
index 07127f30a70a..a4abe9f73080 100644
|
|
--- a/tools/hciattach_rome.h
|
|
+++ b/tools/hciattach_rome.h
|
|
@@ -34,6 +34,13 @@
|
|
#define HCI_EVENT_PKT 0x04
|
|
#define HCI_VENDOR_PKT 0xff
|
|
#define cmd_opcode_pack(ogf, ocf) (unsigned short)((ocf & 0x03ff)|(ogf << 10))
|
|
+
|
|
+#define NVITEM 0
|
|
+#define RDWR_PROT 1
|
|
+#define NVITEM_SIZE 2
|
|
+#define PERSIST_HEADER_LEN 3
|
|
+#define BD_ADDR_LEN 6
|
|
+
|
|
unsigned char vnd_local_bd_addr[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
typedef enum {
|
|
USERIAL_OP_FLOW_ON,
|