You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/05/19 06:33:19 UTC
[08/12] incubator-mynewt-core git commit: bletiny - Various changes
to reduce code size.
bletiny - Various changes to reduce code size.
These changes are necessary to fit a security-enabled bletiny image on
an nRF51dk.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a12f64da
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a12f64da
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a12f64da
Branch: refs/heads/develop
Commit: a12f64dacbd9b3ba2fa9ffcb2b76957b8389ff77
Parents: c16e6c1
Author: Christopher Collins <cc...@apache.org>
Authored: Wed May 18 16:09:49 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed May 18 16:10:33 2016 -0700
----------------------------------------------------------------------
apps/bletiny/pkg.yml | 5 ++
apps/bletiny/src/bletiny_priv.h | 1 -
apps/bletiny/src/cmd.c | 53 ++--------------
apps/bletiny/src/main.c | 119 ++++++++++-------------------------
4 files changed, 43 insertions(+), 135 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a12f64da/apps/bletiny/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml
index 84e0bfa..97e4332 100644
--- a/apps/bletiny/pkg.yml
+++ b/apps/bletiny/pkg.yml
@@ -29,3 +29,8 @@ pkg.deps:
- net/nimble/host
- libs/console/full
- libs/shell
+
+pkg.cflags:
+ # Reduce the log level from DEBUG to INFO. This is necessary to fit
+ # bletiny on the nRF51dk.
+ - "-DLOG_LEVEL=2"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a12f64da/apps/bletiny/src/bletiny_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny_priv.h b/apps/bletiny/src/bletiny_priv.h
index 279f96b..5ecf2e5 100644
--- a/apps/bletiny/src/bletiny_priv.h
+++ b/apps/bletiny/src/bletiny_priv.h
@@ -164,7 +164,6 @@ int bletiny_update_conn(uint16_t conn_handle,
void bletiny_chrup(uint16_t attr_handle);
int bletiny_l2cap_update(uint16_t conn_handle,
struct ble_l2cap_sig_update_params *params);
-int bletiny_show_rssi(uint16_t conn_handle);
int bletiny_sec_start(uint16_t conn_handle);
int bletiny_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
uint64_t rand_val, int auth);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a12f64da/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 5015157..88ea88b 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -96,7 +96,7 @@ cmd_print_chr(struct bletiny_chr *chr)
}
static void
-cmd_print_svc(struct bletiny_svc *svc, int print_chrs)
+cmd_print_svc(struct bletiny_svc *svc)
{
struct bletiny_chr *chr;
@@ -105,10 +105,8 @@ cmd_print_svc(struct bletiny_svc *svc, int print_chrs)
print_uuid(svc->svc.uuid128);
console_printf("\n");
- if (print_chrs) {
- SLIST_FOREACH(chr, &svc->chrs, next) {
- cmd_print_chr(chr);
- }
+ SLIST_FOREACH(chr, &svc->chrs, next) {
+ cmd_print_chr(chr);
}
}
@@ -870,7 +868,7 @@ cmd_show_chr(int argc, char **argv)
console_printf("\n");
SLIST_FOREACH(svc, &conn->svcs, next) {
- cmd_print_svc(svc, 1);
+ cmd_print_svc(svc);
}
}
@@ -894,53 +892,10 @@ cmd_show_conn(int argc, char **argv)
return 0;
}
-static int
-cmd_show_rssi(int argc, char **argv)
-{
- uint16_t conn_handle;
- int rc;
-
- conn_handle = parse_arg_uint16("conn", &rc);
- if (rc != 0) {
- return rc;
- }
-
- rc = bletiny_show_rssi(conn_handle);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static int
-cmd_show_svc(int argc, char **argv)
-{
- struct bletiny_conn *conn;
- struct bletiny_svc *svc;
- int i;
-
- for (i = 0; i < bletiny_num_conns; i++) {
- conn = bletiny_conns + i;
-
- console_printf("CONNECTION: handle=%d addr=", conn->handle);
- print_addr(conn->addr);
- console_printf("\n");
-
- SLIST_FOREACH(svc, &conn->svcs, next) {
- cmd_print_svc(svc, 0);
- }
- }
-
- return 0;
-}
-
static struct cmd_entry cmd_show_entries[] = {
{ "addr", cmd_show_addr },
{ "chr", cmd_show_chr },
{ "conn", cmd_show_conn },
- { "rssi", cmd_show_rssi },
- { "svc", cmd_show_svc },
{ NULL, NULL }
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a12f64da/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index d3d27f8..42c93c9 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -103,12 +103,6 @@ bssnz_t os_stack_t bletiny_stack[BLETINY_STACK_SIZE];
static struct log_handler bletiny_log_console_handler;
struct log bletiny_log;
-struct bletiny_conn ble_shell_conns[NIMBLE_OPT(MAX_CONNECTIONS)];
-int bletiny_num_conns;
-
-void
-bletest_inc_adv_pkt_num(void) { }
-
bssnz_t struct bletiny_conn bletiny_conns[NIMBLE_OPT(MAX_CONNECTIONS)];
int bletiny_num_conns;
@@ -141,6 +135,10 @@ static void
bletiny_print_error(char *msg, uint16_t conn_handle,
struct ble_gatt_error *error)
{
+ if (msg == NULL) {
+ msg = "ERROR";
+ }
+
console_printf("%s: conn_handle=%d status=%d att_handle=%d\n",
msg, conn_handle, error->status, error->att_handle);
}
@@ -180,9 +178,9 @@ static void
bletiny_print_key_exchange_parms(struct ble_gap_key_parms *key_params)
{
if (key_params->is_ours) {
- console_printf("Our Keys Sent to Peer\n");
+ console_printf("keys; us --> peer\n");
} else {
- console_printf("Keys Received from Peer\n");
+ console_printf("keys; peer --> us\n");
}
if (key_params->ltk_valid) {
@@ -488,8 +486,9 @@ bletiny_svc_add(uint16_t conn_handle, struct ble_gatt_service *gatt_svc)
conn = bletiny_conn_find(conn_handle);
if (conn == NULL) {
- console_printf("RECEIVED SERVICE FOR UNKNOWN CONNECTION; HANDLE=%d\n",
- conn_handle);
+ BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
+ "HANDLE=%d\n",
+ conn_handle);
return NULL;
}
@@ -501,7 +500,7 @@ bletiny_svc_add(uint16_t conn_handle, struct ble_gatt_service *gatt_svc)
svc = os_memblock_get(&bletiny_svc_pool);
if (svc == NULL) {
- console_printf("OOM WHILE DISCOVERING SERVICE\n");
+ BLETINY_LOG(DEBUG, "OOM WHILE DISCOVERING SERVICE\n");
return NULL;
}
memset(svc, 0, sizeof *svc);
@@ -572,15 +571,16 @@ bletiny_chr_add(uint16_t conn_handle, uint16_t svc_start_handle,
conn = bletiny_conn_find(conn_handle);
if (conn == NULL) {
- console_printf("RECEIVED SERVICE FOR UNKNOWN CONNECTION; HANDLE=%d\n",
- conn_handle);
+ BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
+ "HANDLE=%d\n",
+ conn_handle);
return NULL;
}
svc = bletiny_svc_find(conn, svc_start_handle, NULL);
if (svc == NULL) {
- console_printf("CAN'T FIND SERVICE FOR DISCOVERED CHR; HANDLE=%d\n",
- conn_handle);
+ BLETINY_LOG(DEBUG, "CAN'T FIND SERVICE FOR DISCOVERED CHR; HANDLE=%d\n",
+ conn_handle);
return NULL;
}
@@ -592,7 +592,7 @@ bletiny_chr_add(uint16_t conn_handle, uint16_t svc_start_handle,
chr = os_memblock_get(&bletiny_chr_pool);
if (chr == NULL) {
- console_printf("OOM WHILE DISCOVERING CHARACTERISTIC\n");
+ BLETINY_LOG(DEBUG, "OOM WHILE DISCOVERING CHARACTERISTIC\n");
return NULL;
}
memset(chr, 0, sizeof *chr);
@@ -662,22 +662,24 @@ bletiny_dsc_add(uint16_t conn_handle, uint16_t chr_def_handle,
conn = bletiny_conn_find(conn_handle);
if (conn == NULL) {
- console_printf("RECEIVED SERVICE FOR UNKNOWN CONNECTION; HANDLE=%d\n",
- conn_handle);
+ BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
+ "HANDLE=%d\n",
+ conn_handle);
return NULL;
}
svc = bletiny_svc_find_range(conn, chr_def_handle);
if (svc == NULL) {
- console_printf("CAN'T FIND SERVICE FOR DISCOVERED DSC; HANDLE=%d\n",
- conn_handle);
+ BLETINY_LOG(DEBUG, "CAN'T FIND SERVICE FOR DISCOVERED DSC; HANDLE=%d\n",
+ conn_handle);
return NULL;
}
chr = bletiny_chr_find(svc, chr_def_handle, NULL);
if (chr == NULL) {
- console_printf("CAN'T FIND CHARACTERISTIC FOR DISCOVERED DSC; "
- "HANDLE=%d\n", conn_handle);
+ BLETINY_LOG(DEBUG, "CAN'T FIND CHARACTERISTIC FOR DISCOVERED DSC; "
+ "HANDLE=%d\n",
+ conn_handle);
return NULL;
}
@@ -705,37 +707,12 @@ bletiny_dsc_add(uint16_t conn_handle, uint16_t chr_def_handle,
return dsc;
}
-static void
-bletiny_start_auto_advertise(void)
-{
- struct ble_hs_adv_fields fields;
- int rc;
-
- if (BLETINY_AUTO_DEVICE_NAME[0] != '\0') {
- memset(&fields, 0, sizeof fields);
-
- fields.name = (uint8_t *)BLETINY_AUTO_DEVICE_NAME;
- fields.name_len = strlen(BLETINY_AUTO_DEVICE_NAME);
- fields.name_is_complete = 1;
- rc = bletiny_set_adv_data(&fields);
- if (rc != 0) {
- return;
- }
-
- rc = bletiny_adv_start(BLE_GAP_DISC_MODE_GEN, BLE_GAP_CONN_MODE_UND,
- NULL, 0, NULL);
- if (rc != 0) {
- return;
- }
- }
-}
-
static int
bletiny_on_mtu(uint16_t conn_handle, struct ble_gatt_error *error,
- uint16_t mtu, void *arg)
+ uint16_t mtu, void *arg)
{
if (error != NULL) {
- bletiny_print_error("ERROR EXCHANGING MTU", conn_handle, error);
+ bletiny_print_error(NULL, conn_handle, error);
} else {
console_printf("mtu exchange complete: conn_handle=%d mtu=%d\n",
conn_handle, mtu);
@@ -749,7 +726,7 @@ bletiny_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_service *service, void *arg)
{
if (error != NULL) {
- bletiny_print_error("ERROR DISCOVERING SERVICE", conn_handle, error);
+ bletiny_print_error(NULL, conn_handle, error);
} else if (service != NULL) {
bletiny_svc_add(conn_handle, service);
} else {
@@ -768,8 +745,7 @@ bletiny_on_disc_c(uint16_t conn_handle, struct ble_gatt_error *error,
svc_start_handle = (intptr_t)arg;
if (error != NULL) {
- bletiny_print_error("ERROR DISCOVERING CHARACTERISTIC", conn_handle,
- error);
+ bletiny_print_error(NULL, conn_handle, error);
} else if (chr != NULL) {
bletiny_chr_add(conn_handle, svc_start_handle, chr);
} else {
@@ -785,8 +761,7 @@ bletiny_on_disc_d(uint16_t conn_handle, struct ble_gatt_error *error,
void *arg)
{
if (error != NULL) {
- bletiny_print_error("ERROR DISCOVERING DESCRIPTOR", conn_handle,
- error);
+ bletiny_print_error(NULL, conn_handle, error);
} else if (dsc != NULL) {
bletiny_dsc_add(conn_handle, chr_def_handle, dsc);
} else {
@@ -801,8 +776,7 @@ bletiny_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg)
{
if (error != NULL) {
- bletiny_print_error("ERROR READING CHARACTERISTIC", conn_handle,
- error);
+ bletiny_print_error(NULL, conn_handle, error);
} else if (attr != NULL) {
console_printf("characteristic read; conn_handle=%d "
"attr_handle=%d len=%d value=", conn_handle,
@@ -821,8 +795,7 @@ bletiny_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg)
{
if (error != NULL) {
- bletiny_print_error("ERROR WRITING CHARACTERISTIC", conn_handle,
- error);
+ bletiny_print_error(NULL, conn_handle, error);
} else {
console_printf("characteristic write complete; conn_handle=%d "
"attr_handle=%d len=%d value=", conn_handle,
@@ -842,8 +815,7 @@ bletiny_on_write_reliable(uint16_t conn_handle, struct ble_gatt_error *error,
int i;
if (error != NULL) {
- bletiny_print_error("ERROR WRITING CHARACTERISTICS RELIABLY",
- conn_handle, error);
+ bletiny_print_error(NULL, conn_handle, error);
} else {
console_printf("characteristic write reliable complete; "
"conn_handle=%d", conn_handle);
@@ -874,7 +846,7 @@ bletiny_on_notify(uint16_t conn_handle, uint16_t attr_handle,
static int
bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
- void *arg)
+ void *arg)
{
int authenticated;
int conn_idx;
@@ -896,13 +868,9 @@ bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
}
} else {
conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
- if (conn_idx == -1) {
- console_printf("UNKNOWN CONNECTION\n");
- } else {
+ if (conn_idx != -1) {
bletiny_conn_delete_idx(conn_idx);
}
-
- bletiny_start_auto_advertise();
}
}
return 0;
@@ -1290,23 +1258,6 @@ bletiny_l2cap_update(uint16_t conn_handle,
}
int
-bletiny_show_rssi(uint16_t conn_handle)
-{
- int8_t rssi;
- int rc;
-
- rc = ble_hci_util_read_rssi(conn_handle, &rssi);
- if (rc != 0) {
- console_printf("failure to read rssi; rc=%d\n", rc);
- return rc;
- }
-
- console_printf("rssi=%d\n", rssi);
-
- return 0;
-}
-
-int
bletiny_sec_start(uint16_t conn_handle)
{
#if !NIMBLE_OPT(SM)
@@ -1353,8 +1304,6 @@ bletiny_task_handler(void *arg)
ble_att_set_notify_cb(bletiny_on_notify, NULL);
- bletiny_start_auto_advertise();
-
while (1) {
ev = os_eventq_get(&bletiny_evq);
switch (ev->ev_type) {