Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 80cd4fd96 -> 147097ac0


Implement local version info command


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/147097ac
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/147097ac
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/147097ac

Branch: refs/heads/master
Commit: 147097ac0059b9cede9d710550c9625f10f00001
Parents: 80cd4fd
Author: wes3 <w...@micosa.io>
Authored: Mon Jan 25 16:43:54 2016 -0800
Committer: wes3 <w...@micosa.io>
Committed: Mon Jan 25 16:44:01 2016 -0800

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_hci.c  | 69 ++++++++++++++++++++++++++--
 net/nimble/host/include/host/host_hci.h |  1 +
 net/nimble/host/src/host_dbg.c          | 24 ++++++++--
 net/nimble/host/src/host_hci_cmd.c      | 10 ++++
 net/nimble/include/nimble/hci_common.h  | 38 +++++++++++++++
 project/bletest/src/main.c              |  5 ++
 6 files changed, 138 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c 
b/net/nimble/controller/src/ble_ll_hci.c
index da29324..f09f958 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -97,6 +97,26 @@ ble_ll_hci_send_noop(void)
     return rc;
 }
 
+static int
+ble_ll_hci_rd_local_version(uint8_t *rspbuf, uint8_t *rsplen)
+{    
+    uint16_t hci_rev;
+    uint16_t lmp_subver;
+    uint16_t mfrg;
+
+    hci_rev = 0;
+    lmp_subver = 0;
+    mfrg = 0xFFFF;  /* XXXX: to be replaced by actual MFRG */
+
+    /* Place the data packet length and number of packets in the buffer */
+    rspbuf[0] = BLE_HCI_VER_BCS_4_2;
+    htole16(rspbuf + 1, hci_rev);
+    rspbuf[3] = BLE_LMP_VER_BCS_4_2;
+    htole16(rspbuf + 4, mfrg);
+    htole16(rspbuf + 6, lmp_subver);
+    *rsplen = BLE_HCI_RD_LOC_VER_INFO_RSPLEN;
+    return BLE_ERR_SUCCESS;
+}
 
 /**
  * ll hci set le event mask
@@ -452,6 +472,44 @@ ble_ll_hci_ctlr_bb_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, 
uint8_t *rsplen)
     return rc;
 }
 
+static int
+ble_ll_hci_info_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
+{
+    int rc;
+    uint8_t len;
+    uint8_t *rspbuf;
+
+    /* Assume error; if all pass rc gets set to 0 */
+    rc = BLE_ERR_INV_HCI_CMD_PARMS;
+
+    /* Get length from command */
+    len = cmdbuf[sizeof(uint16_t)];
+
+    /* 
+     * The command response pointer points into the same buffer as the
+     * command data itself. That is fine, as each command reads all the data
+     * before crafting a response.
+     */ 
+    rspbuf = cmdbuf + BLE_HCI_EVENT_CMD_COMPLETE_MIN_LEN;
+
+    /* Move past HCI command header */
+    cmdbuf += BLE_HCI_CMD_HDR_LEN;
+
+    switch (ocf) {
+    case BLE_HCI_OCF_IP_RD_LOCAL_VER:
+        if (len == 0) {
+            rc = ble_ll_hci_rd_local_version(rspbuf, rsplen);
+        }
+        break;
+    default:
+        rc = BLE_ERR_UNKNOWN_HCI_CMD;
+        break;
+    }
+
+    return rc;
+}
+
+
 void
 ble_ll_hci_cmd_proc(struct os_event *ev)
 {
@@ -480,15 +538,18 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
     rsplen = 0;
 
     switch (ogf) {
-    case BLE_HCI_OGF_LE:
-        rc = ble_ll_hci_le_cmd_proc(cmdbuf, ocf, &rsplen);
-        break;
     case BLE_HCI_OGF_LINK_CTRL:
         rc = ble_ll_hci_link_ctrl_cmd_proc(cmdbuf, ocf, &rsplen);
         break;
     case BLE_HCI_OGF_CTLR_BASEBAND:
         rc = ble_ll_hci_ctlr_bb_cmd_proc(cmdbuf, ocf, &rsplen);
         break;
+    case BLE_HCI_OGF_INFO_PARAMS:
+        rc = ble_ll_hci_info_params_cmd_proc(cmdbuf, ocf, &rsplen);
+        break;
+    case BLE_HCI_OGF_LE:
+        rc = ble_ll_hci_le_cmd_proc(cmdbuf, ocf, &rsplen);
+        break;
     default:
         /* XXX: Need to support other OGF. For now, return unsupported */
         rc = BLE_ERR_UNKNOWN_HCI_CMD;
@@ -505,7 +566,7 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
         htole16(cmdbuf + 3, opcode);
         cmdbuf[5] = (uint8_t)rc;
     } else {
-        /* Create a command complete event with status from command */
+        /* Create a command status event */
         rc -= (BLE_ERR_MAX + 1);
         cmdbuf[0] = BLE_HCI_EVCODE_COMMAND_STATUS;
         cmdbuf[1] = 4;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h 
b/net/nimble/host/include/host/host_hci.h
index 6d94a9d..1c13b20 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -26,6 +26,7 @@ int host_hci_event_rx(uint8_t *data);
 int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata);
 int host_hci_cmd_set_event_mask(uint64_t event_mask);
 int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
+int host_hci_cmd_rd_local_version(void);
 int host_hci_cmd_le_set_scan_rsp_data(uint8_t *data, uint8_t len);
 int host_hci_cmd_le_set_adv_data(uint8_t *data, uint8_t len);
 int host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index bdff5b9..abe1776 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -196,26 +196,40 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t 
len)
     uint8_t ogf;
     uint8_t ocf;
     uint16_t opcode;
-    char parmbuf[32];
 
     opcode = le16toh(evdata + 1);
     ogf = BLE_HCI_OGF(opcode);
     ocf = BLE_HCI_OCF(opcode);
 
+    console_printf("Command Complete: cmd_pkts=%u ocf=0x%x ogf=0x%x ",
+                   evdata[0], ocf, ogf);
+
     /* Display parameters based on command. */
-    parmbuf[0] = '\0';
     if (ogf == BLE_HCI_OGF_LE) {
         switch (ocf) {
         case BLE_HCI_OCF_LE_SET_ADV_DATA:
-            snprintf(parmbuf, 12, "status=%u ", evdata[3]);
+            console_printf("status=%u", evdata[3]);
+            break;
+        default:
+            break;
+        }
+    } else if (ogf == BLE_HCI_OGF_INFO_PARAMS) {
+        switch (ocf) {
+        case BLE_HCI_OCF_IP_RD_LOCAL_VER:
+            console_printf("status=%u ", evdata[3]);
+            if (evdata[3] == BLE_ERR_SUCCESS) {
+                console_printf("hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
+                               "lmp_subver=%u", evdata[4], le16toh(evdata + 5),
+                               evdata[7], le16toh(evdata + 8), 
+                               le16toh(evdata + 10));
+            }
             break;
         default:
             break;
         }
     }
+    console_printf("\n");
 
-    console_printf("Command Complete: cmd_pkts=%u ocf=0x%x ogf=0x%x %s\n",
-                   evdata[0], ocf, ogf, parmbuf);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c 
b/net/nimble/host/src/host_hci_cmd.c
index 304efab..7fe3f0e 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -222,6 +222,16 @@ host_hci_cmd_le_set_rand_addr(uint8_t *addr)
 }
 
 int
+host_hci_cmd_rd_local_version(void)
+{
+    int rc;
+
+    rc = host_hci_cmd_send(BLE_HCI_OGF_INFO_PARAMS,
+                           BLE_HCI_OCF_IP_RD_LOCAL_VER, 0, NULL);
+    return rc;
+}
+
+int
 host_hci_cmd_set_event_mask(uint64_t event_mask)
 {
     int rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h 
b/net/nimble/include/nimble/hci_common.h
index 53278bc..985ae5f 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -62,6 +62,34 @@
 /* Set event mask */
 #define BLE_HCI_SET_EVENT_MASK_LEN          (8)
 
+/* List of OCF for Info Param commands (OGF=0x04) */
+#define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
+
+/* Command specific definitions */
+/* NOTE: does not include status field in command complete event! */
+#define BLE_HCI_RD_LOC_VER_INFO_RSPLEN      (8)
+
+/* Bluetooth Assigned numbers for version information.*/
+#define BLE_HCI_VER_BCS_1_0b                (0)
+#define BLE_HCI_VER_BCS_1_1                 (1)
+#define BLE_HCI_VER_BCS_1_2                 (2)
+#define BLE_HCI_VER_BCS_2_0_EDR             (3)
+#define BLE_HCI_VER_BCS_2_1_EDR             (4)
+#define BLE_HCI_VER_BCS_3_0_HCS             (5)
+#define BLE_HCI_VER_BCS_4_0                 (6)
+#define BLE_HCI_VER_BCS_4_1                 (7)
+#define BLE_HCI_VER_BCS_4_2                 (8)
+
+#define BLE_LMP_VER_BCS_1_0b                (0)
+#define BLE_LMP_VER_BCS_1_1                 (1)
+#define BLE_LMP_VER_BCS_1_2                 (2)
+#define BLE_LMP_VER_BCS_2_0_EDR             (3)
+#define BLE_LMP_VER_BCS_2_1_EDR             (4)
+#define BLE_LMP_VER_BCS_3_0_HCS             (5)
+#define BLE_LMP_VER_BCS_4_0                 (6)
+#define BLE_LMP_VER_BCS_4_1                 (7)
+#define BLE_LMP_VER_BCS_4_2                 (8)
+
 /* List of OCF for LE commands (OGF = 0x08) */
 #define BLE_HCI_OCF_LE_SET_EVENT_MASK       (0x0001)
 #define BLE_HCI_OCF_LE_RD_BUF_SIZE          (0x0002)
@@ -413,6 +441,16 @@
 #define BLE_HCI_LE_DATA_LEN_CHG_LEN         (11)
 
 /*--- Shared data structures ---*/
+/* Read local version information (OGF=0x0004, OCF=0x0001) */
+struct hci_loc_ver_info
+{
+   uint8_t status;
+   uint8_t hci_version;
+   uint16_t hci_revision;
+   uint8_t lmp_pal_version;
+   uint16_t mfrg_name;
+   uint8_t lmp_pal_subversion;
+};
 
 /* set advertising parameters command (ocf = 0x0006) */
 struct hci_adv_params

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/147097ac/project/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/project/bletest/src/main.c b/project/bletest/src/main.c
index 3793a27..9a03295 100755
--- a/project/bletest/src/main.c
+++ b/project/bletest/src/main.c
@@ -632,6 +632,11 @@ bletest_task_handler(void *arg)
     assert(rc == 0);
     host_hci_outstanding_opcode = 0;
 
+    /* Turn on all events */
+    rc = host_hci_cmd_rd_local_version();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
     /* Wait some time before starting */
     os_time_delay(OS_TICKS_PER_SEC);
 

Reply via email to