Skip to contentSkip to conversation

MeshCtl - Mesh GATT Client Provisioner

PATCH In review Brian Gix 4 participants 12 messages Aug 14, 2017 – Aug 21, 2017 Page 2 of 2

Subsystems (3)
lore
Share & tools
lore
#7 lore raw

Re: [PATCH 4/5] mesh: Baseline Mesh implementation

In reply to Gix, Brian

Hi Brian,

Quoted 3 lines · Brian

Hi Luiz,

We actually use the agent.c code for Out-Of-Band data input during Provisioning.

Which seems that was based on client/agent.c though there exists rl_prompt_input and rl_release_prompt which basically does the same thing now, but with introduction of input_request the handling becomes quite a bit different.

I tried doing the conversion myself but it makes very no sense to me to name this agent, in fact much of what it does with types, HEXADECIMAL, etc could be done using different callbacks instead of a global variable.

Quoted 11,457 lines
Quoted 11,457 lines

-----Original Message-----
From: Luiz Augusto von Dentz [mailto:[email protected]]
Sent: Tuesday, August 15, 2017 2:07 AM
To: Gix, Brian <[email protected]>
Cc: [email protected]; Marcel Holtmann <[email protected]>
Subject: Re: [PATCH 4/5] mesh: Baseline Mesh implementation

Hi Brian,

Quoted 7 lines · Brian Gix
---
 mesh/agent.c         |  276 ++++++
 mesh/config-client.c |  667 +++++++++++++++
 mesh/config-server.c |  165 ++++
 mesh/crypto.c        | 1168 ++++++++++++++++++++++++++
 mesh/gatt.c          |  609 ++++++++++++++
 mesh/main.c          | 2269

++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 1 line
 mesh/net.c           | 2184

++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 30 lines
 mesh/node.c          |  879 +++++++++++++++++++
 mesh/onoff-model.c   |  306 +++++++
 mesh/prov-db.c       | 1599 +++++++++++++++++++++++++++++++++++
 mesh/prov.c          |  664 +++++++++++++++
 mesh/util.c          |  369 ++++++++
 12 files changed, 11155 insertions(+)
 create mode 100644 mesh/agent.c
 create mode 100644 mesh/config-client.c
 create mode 100644 mesh/config-server.c
 create mode 100644 mesh/crypto.c
 create mode 100644 mesh/gatt.c
 create mode 100644 mesh/main.c
 create mode 100644 mesh/net.c
 create mode 100644 mesh/node.c
 create mode 100644 mesh/onoff-model.c
 create mode 100644 mesh/prov-db.c
 create mode 100644 mesh/prov.c
 create mode 100644 mesh/util.c
mesh/agent.c new file +5 -0
new file mode 100644
index 0000000..0944862
@@ -0,0 +1,276 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/agent.c line 15

Quoted 10 lines
mesh/agent.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/agent.c

Quoted 5 lines
mesh/agent.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 53 lines
mesh/agent.c new file +53 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <readline/readline.h>
+
+#include <glib.h>
+
+#include <lib/bluetooth.h>
+#include "client/display.h"
+#include "util.h"
+#include "agent.h"
+
+#define AGENT_PROMPT   COLOR_RED "[agent]" COLOR_OFF " "
+
+static char *agent_saved_prompt = NULL;
+static int agent_saved_point = 0;
+
+struct input_request {
+       oob_type_t type;
+       uint16_t len;
+       agent_input_cb cb;
+       void *user_data;
+};
+
+static struct input_request pending_request = {NONE, 0, NULL, NULL};
+
+static void agent_prompt(const char *msg)
+{
+       char *prompt;
+
+       /* Normal use should not prompt for user input to the agent a second
+        * time before it releases the prompt, but we take a safe action. */
+       if (agent_saved_prompt)
+               return;
+
+       agent_saved_point = rl_point;
+       agent_saved_prompt = g_strdup(rl_prompt);
+
+       rl_set_prompt("");
+       rl_redisplay();
+
+       prompt = g_strdup_printf(AGENT_PROMPT "%s", msg);
+       rl_set_prompt(prompt);
+       g_free(prompt);
+

mesh/agent.c

Quoted 10 lines
mesh/agent.c new file +10 -0
+       rl_replace_line("", 0);
+       rl_redisplay();
+}
+
+static void agent_release_prompt(void)
+{
+       if (!agent_saved_prompt)
+               return;
+
+       /* This will cause rl_expand_prompt to re-run over the last prompt,

but

Quoted 131 lines
mesh/agent.c new file +131 -0
+        * our prompt doesn't expand anyway. */
+       rl_set_prompt(agent_saved_prompt);
+       rl_replace_line("", 0);
+       rl_point = agent_saved_point;
+       rl_redisplay();
+
+       g_free(agent_saved_prompt);
+       agent_saved_prompt = NULL;
+}
+
+bool agent_completion(void)
+{
+       if (pending_request.type == NONE)
+               return false;
+
+       return true;
+}
+
+static bool response_hexadecimal(const char *input)
+{
+       uint8_t buf[MAX_HEXADECIMAL_OOB_LEN];
+
+       if (!str2hex(input, strlen(input), buf, pending_request.len) ) {
+               rl_printf("Incorrect input: expecting %d hex octets\n",
+                         pending_request.len);
+               return false;
+       }
+
+       if (pending_request.cb)
+               pending_request.cb(HEXADECIMAL, buf, pending_request.len,
+                                       pending_request.user_data);
+       return true;
+}
+
+static bool response_decimal(const char *input)
+{
+       uint8_t buf[DECIMAL_OOB_LEN];
+
+       if (strlen(input) > pending_request.len)
+               return false;
+
+       bt_put_be32(atoi(input), buf);
+
+       if (pending_request.cb)
+               pending_request.cb(DECIMAL, buf, DECIMAL_OOB_LEN,
+                                       pending_request.user_data);
+
+       return true;
+}
+
+static void response_ascii(const char *input)
+{
+       if (pending_request.cb)
+               pending_request.cb(ASCII, (uint8_t *) input, strlen(input),
+                                       pending_request.user_data);
+}
+
+bool agent_input(const char *input)
+{
+       bool repeat = false;
+
+       if (pending_request.type == NONE)
+               return false;
+
+       switch (pending_request.type) {
+       case HEXADECIMAL:
+               if (!response_hexadecimal(input))
+                       repeat = true;
+               break;
+       case DECIMAL:
+               if (!response_decimal(input))
+                       repeat = true;
+               break;
+       case ASCII:
+               response_ascii(input);
+               break;
+       case OUTPUT:
+               repeat = true;
+       case NONE:
+       default:
+               break;
+       };
+
+       if (!repeat) {
+               pending_request.type = NONE;
+               pending_request.len = 0;
+               pending_request.cb = NULL;
+               pending_request.user_data = NULL;
+
+               agent_release_prompt();
+       }
+
+       return true;
+}
+
+void agent_release(void)
+{
+       agent_release_prompt();
+}
+
+static bool request_hexadecimal(uint16_t len)
+{
+       if (len > MAX_HEXADECIMAL_OOB_LEN)
+               return false;
+
+       rl_printf("Request hexadecimal key (hex %d octets)\n", len);
+       agent_prompt("Enter key (hex number): ");
+
+       return true;
+}
+
+static uint32_t power_ten(uint8_t power)
+{
+       uint32_t ret = 1;
+
+       while (power--)
+               ret *= 10;
+
+       return ret;
+}
+
+static bool request_decimal(uint16_t len)
+{
+       rl_printf("Request decimal key (0 - %d)\n", power_ten(len) - 1);
+       agent_prompt("Enter Numeric key: ");
+
+       return true;
+}
+
+static bool request_ascii(uint16_t len)
+{

mesh/agent.c

Quoted 10 lines
mesh/agent.c new file +10 -0
+       if (len != MAX_ASCII_OOB_LEN)
+               return false;
+
+       rl_printf("Request ASCII key (max characters %d)\n", len);
+       agent_prompt("Enter key (ascii string): ");
+
+       return true;
+}
+
+bool agent_input_request(oob_type_t type, uint16_t max_len,

agent_input_cb cb,

Quoted 42 lines
mesh/agent.c new file +42 -0
+                               void *user_data)
+{
+       bool result;
+
+       if (pending_request.type != NONE)
+               return FALSE;
+
+       switch (type) {
+       case HEXADECIMAL:
+               result = request_hexadecimal(max_len);
+               break;
+       case DECIMAL:
+               result = request_decimal(max_len);
+               break;
+       case ASCII:
+               result = request_ascii(max_len);
+               break;
+       case NONE:
+       case OUTPUT:
+       default:
+               return false;
+       };
+
+       if (result) {
+               pending_request.type = type;
+               pending_request.len = max_len;
+               pending_request.cb = cb;
+               pending_request.user_data = user_data;
+
+               return true;
+       }
+
+       return false;
+}
+
+bool agent_output_request(const char* str)
+{
+       if (pending_request.type != NONE)
+               return false;
+
+       pending_request.type = OUTPUT;
+       agent_prompt(str);

mesh/agent.c line 276

Quoted 10 lines
mesh/agent.c new file +10 -0
+       return true;
+}
+
+void agent_output_request_cancel(void)
+{
+       if (pending_request.type != OUTPUT)
+               return;
+       pending_request.type = NONE;
+       agent_release_prompt();
+}

The whole agent.c can be removed as well.

Quoted 11 lines
mesh/config-client.c new file +5 -0
new file mode 100644
index 0000000..a0f6eee
@@ -0,0 +1,667 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/config-client.c line 15

Quoted 10 lines
mesh/config-client.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/config-client.c line 20

Quoted 5 lines
mesh/config-client.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 658 lines
mesh/config-client.c new file +647 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <sys/uio.h>
+#include <wordexp.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+
+#include "src/shared/util.h"
+#include "client/display.h"
+#include "mesh-net.h"
+#include "keys.h"
+#include "net.h"
+#include "node.h"
+#include "prov-db.h"
+#include "util.h"
+#include "config-model.h"
+
+#define MIN_COMPOSITION_LEN 16
+
+static bool client_msg_recvd(uint16_t src, uint8_t *data,
+                               uint16_t len, void *user_data)
+{
+       uint32_t opcode;
+       struct mesh_node *node;
+       uint16_t app_idx, net_idx, addr;
+       uint32_t mod_id;
+       uint16_t primary;
+       uint16_t ele_addr;
+       uint8_t ele_idx;
+       struct mesh_publication pub;
+       int n;
+
+       if (mesh_opcode_get(data, len, &opcode, &n)) {
+               len -= n;
+               data += n;
+       } else
+               return false;
+
+       if (IS_UNICAST(src)) {
+               node = node_find_by_addr(src);
+       } else
+               node = NULL;
+
+       if (!node)
+               return false;
+
+       primary = node_get_primary(node);
+       if (primary != src)
+               return false;
+
+       switch (opcode & ~OP_UNRELIABLE) {
+       default:
+               return false;
+
+       case OP_DEV_COMP_STATUS:
+               if (len < MIN_COMPOSITION_LEN || !node)
+                       break;
+               if (node_parse_composition(node, data, len)) {
+                       if (!prov_db_add_node_composition(node, data, len))
+                               break;
+               }
+
+               if (node_get_composition(node))
+                       prov_db_print_node_composition(node);
+               break;
+
+       case OP_APPKEY_STATUS:
+               if (len != 4)
+                       break;
+
+               rl_printf("Node %4.4x AppKey Status %s\n", src,
+                                               mesh_status_str(data[0]));
+               net_idx = get_le16(data + 1) & 0xfff;
+               app_idx = get_le16(data + 2) >> 4;
+
+               rl_printf("\tNetKey %3.3x, AppKey %3.3x\n", net_idx, app_idx);
+
+               if (data[0] != MESH_STATUS_SUCCESS &&
+                               data[0] != MESH_STATUS_IDX_ALREADY_STORED &&
+                               node_app_key_delete(node, net_idx, app_idx))
+                       prov_db_node_keys(node, node_get_app_keys(node),
+                                                               "appKeys");
+               break;
+
+       case OP_NETKEY_STATUS:
+               if (len != 3)
+                       break;
+
+               rl_printf("Node %4.4x NetKey Status %s\n", src,
+                                               mesh_status_str(data[0]));
+               net_idx = get_le16(data + 1) & 0xfff;
+
+               rl_printf("\tNetKey %3.3x\n", net_idx);
+
+               if (data[0] != MESH_STATUS_SUCCESS &&
+                               data[0] != MESH_STATUS_IDX_ALREADY_STORED &&
+                                       node_net_key_delete(node, net_idx))
+                       prov_db_node_keys(node, node_get_net_keys(node),
+                                                               "netKeys");
+               break;
+
+       case OP_MODEL_APP_STATUS:
+               if (len != 7 && len != 9)
+                       break;
+
+               rl_printf("Node %4.4x Model App Status %s\n", src,
+                                               mesh_status_str(data[0]));
+               addr = get_le16(data + 1);
+               app_idx = get_le16(data + 3);
+
+               rl_printf("\tElement %4.4x AppIdx %3.3x\n ", addr, app_idx);
+
+               if (len == 7) {
+                       mod_id = get_le16(data + 5);
+                       rl_printf("ModelId %4.4x\n", mod_id);
+                       mod_id = 0xffff0000 | mod_id;
+               } else {
+                       mod_id = get_le16(data + 7);
+                       rl_printf("ModelId %4.4x %4.4x\n", get_le16(data + 5),
+                                                                       mod_id);
+                       mod_id = get_le16(data + 5) << 16 | mod_id;
+               }
+
+               if (data[0] == MESH_STATUS_SUCCESS &&
+                       node_add_binding(node, addr - src, mod_id, app_idx))
+                       prov_db_add_binding(node, addr - src, mod_id, app_idx);
+               break;
+
+       case OP_CONFIG_DEFAULT_TTL_STATUS:
+               if (len != 1)
+                       return true;
+               rl_printf("Node %4.4x Default TTL %d\n", src, data[0]);
+               if (node_set_default_ttl (node, data[0]))
+                       prov_db_node_set_ttl(node, data[0]);
+               break;
+
+       case OP_CONFIG_MODEL_PUB_STATUS:
+               if (len != 12 && len != 14)
+                       return true;
+
+               rl_printf("\nSet publication for node %4.4x status: %s\n", src,
+                               data[0] == MESH_STATUS_SUCCESS ? "Success" :
+                                               mesh_status_str(data[0]));
+
+               if (data[0] != MESH_STATUS_SUCCESS)
+                       return true;
+
+               ele_addr = get_le16(data + 1);
+               mod_id = get_le16(data + 10);
+               if (len == 14)
+                       mod_id = (mod_id << 16)  | get_le16(data + 12);
+               else
+                       mod_id |= 0xffff0000;
+
+               pub.u.addr16 = get_le16(data + 3);
+               pub.app_idx = get_le16(data + 5);
+               pub.ttl = data[7];
+               pub.period = data[8];
+               n = (data[8] & 0x3f);
+               switch (data[8] >> 6) {
+               case 0:
+                       rl_printf("Period: %d ms\n", n * 100);
+                       break;
+               case 2:
+                       n *= 10;
+                       /* fall through */
+               case 1:
+                       rl_printf("Period: %d sec\n", n);
+                       break;
+               case 3:
+                       rl_printf("Period: %d min\n", n * 10);
+                       break;
+               }
+
+               pub.retransmit = data[9];
+               rl_printf("Retransmit count: %d\n", data[9] >> 5);
+               rl_printf("Retransmit Interval Steps: %d\n", data[9] & 0x1f);
+
+               ele_idx = ele_addr - node_get_primary(node);
+
+               /* Local configuration is saved by server */
+               if (node == node_get_local_node())
+                       break;
+
+               if (node_model_pub_set(node, ele_idx, mod_id, &pub))
+                       prov_db_node_set_model_pub(node, ele_idx, mod_id,
+                                    node_model_pub_get(node, ele_idx, mod_id));
+               break;
+       }
+       return true;
+}
+
+static uint32_t target;
+static uint32_t parms[8];
+
+static uint32_t read_input_parameters(const char *args)
+{
+       uint32_t i;
+
+       if (!args)
+               return 0;
+
+       memset(parms, 0xff, sizeof(parms));
+
+       for (i = 0; i < sizeof(parms)/sizeof(parms[0]); i++) {
+               int n;
+
+               sscanf(args, "%x", &parms[i]);
+               if (parms[i] == 0xffffffff)
+                       break;
+
+               n = strcspn(args, " \t");
+               args = args + n + strspn(args + n, " \t");
+       }
+
+       return i;
+}
+
+static void cmd_set_node(const char *args)
+{
+       uint32_t dst;
+       char *end;
+
+       dst = strtol(args, &end, 16);
+       if (end != (args + 4)) {
+               rl_printf("Bad unicast address %s: "
+                                       "expected format 4 digit hex\n", args);
+               target = UNASSIGNED_ADDRESS;
+       } else {
+               rl_printf("Configuring node %4.4x\n", dst);
+               target = dst;
+               set_menu_prompt("config", args);
+       }
+
+}
+
+static bool config_send(uint8_t *buf, uint16_t len)
+{
+       struct mesh_node *node = node_get_local_node();
+       uint16_t primary;
+
+       if(!node)
+               return false;
+
+       primary = node_get_primary(node);
+       if (target != primary)
+               return net_access_layer_send(DEFAULT_TTL, primary,
+                                               target, APP_IDX_DEV, buf, len);
+
+       node_local_data_handler(primary, target, node_get_iv_index(node),
+                               node_get_sequence_number(node), APP_IDX_DEV,
+                               buf, len);
+       return true;
+
+}
+
+static void cmd_get_composition(const char *args)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       struct mesh_node *node;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       node = node_find_by_addr(target);
+
+       if (!node)
+               return;
+
+       n = mesh_opcode_set(OP_DEV_COMP_GET, msg);
+
+       /* By default, use page 0 */
+       msg[n++] = (read_input_parameters(args) == 1) ? parms[0] : 0;
+
+       if (!config_send(msg, n))
+               rl_printf("Failed to send \"GET NODE COMPOSITION\"\n");
+}
+
+static void cmd_net_key(const char *args, uint32_t opcode)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       uint16_t net_idx;
+       uint8_t *key;
+       struct mesh_node *node;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       n = mesh_opcode_set(opcode, msg);
+
+       if (read_input_parameters(args) != 1) {
+               rl_printf("Bad arguments %s\n", args);
+               return;
+       }
+
+       node = node_find_by_addr(target);
+       if (!node) {
+               rl_printf("Node %4.4x\n not found", target);
+               return;
+       }
+
+       net_idx = parms[0];
+
+       if (opcode != OP_NETKEY_DELETE) {
+
+               key = keys_net_key_get(net_idx, true);
+               if (!key) {
+                       rl_printf("Network key with index %4.4x not found\n",
+                                                               net_idx);
+                       return;
+               }
+
+               put_le16(net_idx, &msg[n]);
+               n += 2;
+
+               memcpy(msg + n, key, 16);
+               n += 16;
+       }
+
+       if (!config_send(msg, n)) {
+               rl_printf("Failed to send \"%s NET KEY\"\n",
+                               opcode == OP_NETKEY_ADD ? "ADD" : "DEL");
+               return;
+       }
+
+       if (opcode != OP_NETKEY_DELETE) {
+               if (node_net_key_add(node, net_idx))
+                       prov_db_node_keys(node, node_get_net_keys(node),
+                                                               "netKeys");
+       } else {
+               if (node_net_key_delete(node, net_idx))
+                       prov_db_node_keys(node, node_get_net_keys(node),
+                                                               "netKeys");
+       }
+
+}
+
+static void cmd_add_net_key(const char *args)
+{
+       cmd_net_key(args, OP_NETKEY_ADD);
+}
+
+static void cmd_del_net_key(const char *args)
+{
+       cmd_net_key(args, OP_NETKEY_DELETE);
+}
+
+static void cmd_app_key(const char *args, uint32_t opcode)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       uint16_t net_idx;
+       uint16_t app_idx;
+       uint8_t *key;
+       struct mesh_node *node;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       if (read_input_parameters(args) != 1) {
+               rl_printf("Bad arguments %s\n", args);
+               return;
+       }
+
+       node = node_find_by_addr(target);
+       if (!node) {
+               rl_printf("Node %4.4x\n not found", target);
+               return;
+       }
+
+       n = mesh_opcode_set(opcode, msg);
+
+       app_idx = parms[0];
+       net_idx = keys_app_key_get_bound(app_idx);
+       if (net_idx == NET_IDX_INVALID) {
+               rl_printf("App key with index %4.4x not found\n", app_idx);
+               return;
+       }
+
+       msg[n++] = net_idx & 0xf;
+       msg[n++] = ((net_idx >> 8) & 0xf) |
+               ((app_idx << 4) & 0xf0);
+       msg[n++] = app_idx >> 4;
+
+       if (opcode != OP_APPKEY_DELETE) {
+               key = keys_app_key_get(app_idx, true);
+               if (!key) {
+                       rl_printf("App key %4.4x not found\n", net_idx);
+                       return;
+               }
+
+               memcpy(msg + n, key, 16);
+               n += 16;
+       }
+
+       if (!config_send(msg, n)) {
+               rl_printf("Failed to send \"ADD %s KEY\"\n",
+                               opcode == OP_APPKEY_ADD ? "ADD" : "DEL");
+               return;
+       }
+
+       if (opcode != OP_APPKEY_DELETE) {
+               if (node_app_key_add(node, app_idx))
+                       prov_db_node_keys(node, node_get_app_keys(node),
+                                                               "appKeys");
+       } else {
+               if (node_app_key_delete(node, net_idx, app_idx))
+                       prov_db_node_keys(node, node_get_app_keys(node),
+                                                               "appKeys");
+       }
+}
+
+static void cmd_add_app_key(const char *args)
+{
+       cmd_app_key(args, OP_APPKEY_ADD);
+}
+
+static void cmd_del_app_key(const char *args)
+{
+       cmd_app_key(args, OP_APPKEY_DELETE);
+}
+
+static void cmd_bind(const char *args)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       int parm_cnt;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       parm_cnt = read_input_parameters(args);
+       if (parm_cnt != 3 && parm_cnt != 4) {
+               rl_printf("Bad arguments %s\n", args);
+               return;
+       }
+
+       n = mesh_opcode_set(OP_MODEL_APP_BIND, msg);
+
+       put_le16(target + parms[0], msg + n);
+       n += 2;
+       put_le16(parms[1], msg + n);
+       n += 2;
+       if (parm_cnt == 4) {
+               put_le16(parms[3], msg + n);
+               put_le16(parms[2], msg + n + 2);
+               n += 4;
+       } else {
+               put_le16(parms[2], msg + n);
+               n += 2;
+       }
+
+       if (!config_send(msg, n))
+               rl_printf("Failed to send \"MODEL APP BIND\"\n");
+}
+
+static void cmd_set_ttl(const char *args)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       int parm_cnt;
+       uint8_t ttl;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       n = mesh_opcode_set(OP_CONFIG_DEFAULT_TTL_SET, msg);
+
+       parm_cnt = read_input_parameters(args);
+       if (parm_cnt) {
+               ttl = parms[0] & TTL_MASK;
+       } else
+               ttl = node_get_default_ttl(node_get_local_node());
+
+       msg[n++] = ttl;
+
+       if (!config_send(msg, n))
+               rl_printf("Failed to send \"SET_DEFAULT TTL\"\n");
+}
+
+static void cmd_set_pub(const char *args)
+{
+       uint16_t n;
+       uint8_t msg[32];
+       int parm_cnt;
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       n = mesh_opcode_set(OP_CONFIG_MODEL_PUB_SET, msg);
+
+       parm_cnt = read_input_parameters(args);
+       if (parm_cnt != 5) {
+               rl_printf("Bad arguments: %s\n", args);
+               return;
+       }
+
+       put_le16(parms[0], msg + n);
+       n += 2;
+       /* Publish address */
+       put_le16(parms[1], msg + n);
+       n += 2;
+       /* App key index + credential (set to 0) */
+       put_le16(parms[2], msg + n);
+       n += 2;
+       /* TTL */
+       msg[n++] = DEFAULT_TTL;
+       /* Publish period  step count and step resolution */
+       msg[n++] = parms[3];
+       /* Publish retransmit count & interval steps */
+       msg[n++] = (1 << 5) + 2;
+       /* Model Id */
+       if (parms[4] > 0xffff) {
+               put_le16(parms[4] >> 16, msg + n);
+               put_le16(parms[4], msg + n + 2);
+               n += 4;
+       } else {
+               put_le16(parms[4], msg + n);
+               n += 2;
+       }
+
+       if (!config_send(msg, n))
+               rl_printf("Failed to send \"SET MODEL PUBLICATION\"\n");
+}
+
+static void cmd_default(uint32_t opcode)
+{
+       uint16_t n;
+       uint8_t msg[32];
+
+       if (IS_UNASSIGNED(target)) {
+               rl_printf("Destination not set\n");
+               return;
+       }
+
+       n = mesh_opcode_set(opcode, msg);
+
+       if (!config_send(msg, n))
+               rl_printf("Failed to send command (opcode 0x%x)\n", opcode);
+}
+
+static void cmd_get_ttl(const char *args)
+{
+       cmd_default(OP_CONFIG_DEFAULT_TTL_GET);
+}
+
+static void cmd_back(const char *args)
+{
+       cmd_menu_main(false);
+}
+
+static void cmd_help(const char *args);
+
+static const struct menu_entry cfg_menu[] = {
+       {"target",              "<unicast>",                    cmd_set_node,
+                                               "Set target node to configure"},
+       {"get-composition",     "[<page_num>]",         cmd_get_composition,
+                                               "Get Composition Data"},
+       {"add-netkey",          "<net_idx>",                    cmd_add_net_key,
+                                               "Add network key"},
+       {"del-netkey",          "<net_idx>",                    cmd_del_net_key,
+                                               "Delete network key"},
+       {"add-appkey",          "<app_idx>",                    cmd_add_app_key,
+                                               "Add application key"},
+       {"del-appkey",          "<app_idx>",                    cmd_del_app_key,
+                                               "Delete application key"},
+       {"bind",                "<ele_idx> <app_idx> <mod_id> [cid]",
+                               cmd_bind,       "Bind app key to a model"},
+       {"set-ttl",             "<ttl>",                        cmd_set_ttl,
+                                               "Set default TTL"},
+       {"get-ttl",             NULL,                   cmd_get_ttl,
+                                               "Get default TTL"},
+       {"set-pub", "<ele_addr> <pub_addr> <app_idx> "
+                                               "<period (step|res)> <model>",
+                               cmd_set_pub,    "Set publication"},
+       {"back",                NULL,                           cmd_back,
+                                               "Back to main menu"},
+       {"help",                NULL,                           cmd_help,
+                                               "Config Commands"},
+       {}
+};
+
+static void cmd_help(const char *args)
+{
+       rl_printf("Client Configuration Menu\n");
+       print_cmd_menu(cfg_menu);
+}
+
+void config_set_node(const char *args)
+{
+       cmd_set_node(args);
+}
+
+void config_client_get_composition(uint32_t dst)
+{
+       uint32_t tmp = target;
+
+       target = dst;
+       cmd_get_composition("");
+       target = tmp;
+}
+
+static struct mesh_model_ops client_cbs = {
+       client_msg_recvd,
+               NULL,
+               NULL,
+               NULL
+};
+
+bool config_client_init(void)
+{
+       if (!node_local_model_register(PRIMARY_ELEMENT_IDX,
+                                               CONFIG_CLIENT_MODEL_ID,
+                                               &client_cbs, NULL))
+               return false;
+
+       add_cmd_menu("configure", cfg_menu);
+
+       return true;
+}
mesh/config-server.c new file +5 -0
new file mode 100644
index 0000000..14e5d7b
@@ -0,0 +1,165 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/config-server.c line 15

Quoted 10 lines
mesh/config-server.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/config-server.c line 20

Quoted 5 lines
mesh/config-server.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 156 lines
mesh/config-server.c new file +145 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <sys/uio.h>
+#include <wordexp.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+
+#include "src/shared/util.h"
+#include "client/display.h"
+#include "mesh-net.h"
+#include "keys.h"
+#include "net.h"
+#include "node.h"
+#include "prov-db.h"
+#include "util.h"
+#include "config-model.h"
+
+static bool server_msg_recvd(uint16_t src, uint8_t *data,
+                               uint16_t len, void *user_data)
+{
+       uint32_t opcode;
+       uint8_t msg[32];
+       struct mesh_node *node;
+       uint16_t primary;
+       uint32_t mod_id;
+       uint16_t ele_addr;
+       uint8_t ele_idx;
+       struct mesh_publication pub;
+
+       int n;
+
+       if (mesh_opcode_get(data, len, &opcode, &n)) {
+               len -= n;
+               data += n;
+       } else
+               return false;
+
+       node = node_get_local_node();
+
+       if (!node)
+               return true;
+
+       switch (opcode & ~OP_UNRELIABLE) {
+       default:
+               return false;
+
+       case OP_CONFIG_DEFAULT_TTL_SET:
+               if (len != 1 || data[0] > TTL_MASK || data[0] == 1)
+                       return true;
+
+               if (data[0] <= TTL_MASK) {
+                       node_set_default_ttl(node, data[0]);
+                       prov_db_node_set_ttl(node, data[0]);
+               }
+
+               /* Fall Through */
+
+       case OP_CONFIG_DEFAULT_TTL_GET:
+               n = mesh_opcode_set(OP_CONFIG_DEFAULT_TTL_STATUS, msg);
+               msg[n++] = node_get_default_ttl(node);
+               break;
+
+       case OP_CONFIG_MODEL_PUB_SET:
+               if (len != 11 && len != 13)
+                       return true;
+
+               rl_printf("Set publication\n");
+
+               ele_addr = get_le16(data);
+               mod_id = get_le16(data + 9);
+               if (len == 14)
+                       mod_id = (mod_id << 16)  | get_le16(data + 11);
+               else
+                       mod_id |= 0xffff0000;
+
+               pub.u.addr16 = get_le16(data + 2);
+               pub.app_idx = get_le16(data + 4);
+               pub.ttl = data[6];
+               pub.period = data[7];
+               n = (data[7] & 0x3f);
+               switch (data[7] >> 6) {
+               case 0:
+                       rl_printf("Period: %d ms\n", n * 100);
+                       break;
+               case 2:
+                       n *= 10;
+                       /* fall through */
+               case 1:
+                       rl_printf("Period: %d sec\n", n);
+                       break;
+               case 3:
+                       rl_printf("Period: %d min\n", n * 10);
+                       break;
+               }
+
+               pub.retransmit = data[8];
+               rl_printf("Retransmit count: %d\n", data[8] >> 5);
+               rl_printf("Retransmit Interval Steps: %d\n", data[8] & 0x1f);
+
+               ele_idx = ele_addr - node_get_primary(node);
+
+               if (node_model_pub_set(node, ele_idx, mod_id, &pub)) {
+                       prov_db_node_set_model_pub(node, ele_idx, mod_id,
+                                    node_model_pub_get(node, ele_idx, mod_id));
+               }
+               break;
+       }
+
+       primary = node_get_primary(node);
+       if (src != primary)
+               net_access_layer_send(node_get_default_ttl(node), primary,
+                                       src, APP_IDX_DEV, msg, len);
+       return true;
+}
+
+
+static struct mesh_model_ops server_cbs = {
+       server_msg_recvd,
+               NULL,
+               NULL,
+               NULL
+};
+
+bool config_server_init(void)
+{
+       if (!node_local_model_register(PRIMARY_ELEMENT_IDX,
+                                               CONFIG_SERVER_MODEL_ID,
+                                               &server_cbs, NULL))
+               return false;
+
+       return true;
+}
mesh/crypto.c new file +5 -0
new file mode 100644
index 0000000..189624e
@@ -0,0 +1,1168 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/crypto.c line 15

Quoted 10 lines
mesh/crypto.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/crypto.c line 20

Quoted 5 lines
mesh/crypto.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 103 lines
mesh/crypto.c new file +103 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include <linux/if_alg.h>
+
+#include <glib.h>
+
+#ifndef SOL_ALG
+#define SOL_ALG                279
+#endif
+
+#ifndef ALG_SET_AEAD_AUTHSIZE
+#define ALG_SET_AEAD_AUTHSIZE  5
+#endif
+
+#include "src/shared/util.h"
+#include "mesh-net.h"
+#include "crypto.h"
+
+static int alg_new(int fd, const void *keyval, socklen_t keylen,
+               size_t mic_size)
+{
+       if (setsockopt(fd, SOL_ALG, ALG_SET_KEY, keyval, keylen) < 0) {
+               g_printerr("key");
+               return -1;
+       }
+
+       if (mic_size &&
+               setsockopt(fd, SOL_ALG,
+                       ALG_SET_AEAD_AUTHSIZE, NULL, mic_size) < 0) {
+               g_printerr("taglen");
+               return -1;
+       }
+
+       /* FIXME: This should use accept4() with SOCK_CLOEXEC */
+       return accept(fd, NULL, 0);
+}
+
+static bool alg_encrypt(int fd, const void *inbuf, size_t inlen,
+                                               void *outbuf, size_t outlen)
+{
+       __u32 alg_op = ALG_OP_ENCRYPT;
+       char cbuf[CMSG_SPACE(sizeof(alg_op))];
+       struct cmsghdr *cmsg;
+       struct msghdr msg;
+       struct iovec iov;
+       ssize_t len;
+
+       memset(cbuf, 0, sizeof(cbuf));
+       memset(&msg, 0, sizeof(msg));
+
+       msg.msg_control = cbuf;
+       msg.msg_controllen = sizeof(cbuf);
+
+       cmsg = CMSG_FIRSTHDR(&msg);
+       cmsg->cmsg_level = SOL_ALG;
+       cmsg->cmsg_type = ALG_SET_OP;
+       cmsg->cmsg_len = CMSG_LEN(sizeof(alg_op));
+       memcpy(CMSG_DATA(cmsg), &alg_op, sizeof(alg_op));
+
+       iov.iov_base = (void *) inbuf;
+       iov.iov_len = inlen;
+
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+
+       len = sendmsg(fd, &msg, 0);
+       if (len < 0)
+               return false;
+
+       len = read(fd, outbuf, outlen);
+       if (len < 0)
+               return false;
+
+       return true;
+}
+
+static int aes_ecb_setup(const uint8_t key[16])
+{
+       struct sockaddr_alg salg;
+       int fd, nfd;
+
+       fd = socket(PF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
+       if (fd < 0)
+               return -1;
+
+       memset(&salg, 0, sizeof(salg));
+       salg.salg_family = AF_ALG;
+       strcpy((char *) salg.salg_type, "skcipher");
+       strcpy((char *) salg.salg_name, "ecb(aes)");
+
+       if (bind(fd, (struct sockaddr *) &salg, sizeof(salg)) < 0) {
+               close(fd);
+               return -1;

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       }
+
+       nfd = alg_new(fd, key, 16, 0);
+
+       close(fd);
+
+       return nfd;
+}
+
+static bool aes_ecb(int fd, const uint8_t plaintext[16], uint8_t

encrypted[16])

Quoted 101 lines
mesh/crypto.c new file +101 -0
+{
+       return alg_encrypt(fd, plaintext, 16, encrypted, 16);
+}
+
+static void aes_ecb_destroy(int fd)
+{
+       close(fd);
+}
+
+static bool aes_ecb_one(const uint8_t key[16],
+                       const uint8_t plaintext[16], uint8_t encrypted[16])
+{
+       bool result;
+       int fd;
+
+       fd = aes_ecb_setup(key);
+       if (fd < 0)
+               return false;
+
+       result = aes_ecb(fd, plaintext, encrypted);
+
+       aes_ecb_destroy(fd);
+
+       return result;
+}
+
+/* Maximum message length that can be passed to aes_cmac */
+#define CMAC_MSG_MAX   (64 + 64 + 17)
+
+static int aes_cmac_setup(const uint8_t key[16])
+{
+       struct sockaddr_alg salg;
+       int fd, nfd;
+
+       fd = socket(PF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
+       if (fd < 0)
+               return -1;
+
+       memset(&salg, 0, sizeof(salg));
+       salg.salg_family = AF_ALG;
+       strcpy((char *) salg.salg_type, "hash");
+       strcpy((char *) salg.salg_name, "cmac(aes)");
+
+       if (bind(fd, (struct sockaddr *) &salg, sizeof(salg)) < 0) {
+               close(fd);
+               return -1;
+       }
+
+       nfd = alg_new(fd, key, 16, 0);
+
+       close(fd);
+
+       return nfd;
+}
+
+static bool aes_cmac(int fd, const uint8_t *msg,
+                                       size_t msg_len, uint8_t res[16])
+{
+       ssize_t len;
+
+       if (msg_len > CMAC_MSG_MAX)
+               return false;
+
+       len = send(fd, msg, msg_len, 0);
+       if (len < 0)
+               return false;
+
+       len = read(fd, res, 16);
+       if (len < 0)
+               return false;
+
+       return true;
+}
+
+static void aes_cmac_destroy(int fd)
+{
+       close(fd);
+}
+
+static int aes_cmac_N_start(const uint8_t N[16])
+{
+       int fd;
+
+       fd = aes_cmac_setup(N);
+       return fd;
+}
+
+static bool aes_cmac_one(const uint8_t key[16], const void *msg,
+                                       size_t msg_len, uint8_t res[16])
+{
+       bool result;
+       int fd;
+
+       fd = aes_cmac_setup(key);
+       if (fd < 0)
+               return false;
+
+       result = aes_cmac(fd, msg, msg_len, res);
+
+       aes_cmac_destroy(fd);
+

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       return result;
+}
+
+bool mesh_crypto_aes_cmac(const uint8_t key[16], const uint8_t *msg,
+                                       size_t msg_len, uint8_t res[16])
+{
+       return aes_cmac_one(key, msg, msg_len, res);
+}
+
+bool mesh_crypto_aes_ccm_encrypt(const uint8_t nonce[13], const

uint8_t key[16],

Quoted 155 lines
mesh/crypto.c new file +155 -0
+                                       const uint8_t *aad, uint16_t aad_len,
+                                       const uint8_t *msg, uint16_t msg_len,
+                                       uint8_t *out_msg, void *out_mic,
+                                       size_t mic_size)
+{
+       uint8_t pmsg[16], cmic[16], cmsg[16];
+       uint8_t mic[16], Xn[16];
+       uint16_t blk_cnt, last_blk;
+       bool result;
+       size_t i, j;
+       int fd;
+
+       if (aad_len >= 0xff00) {
+               g_printerr("Unsupported AAD size");
+               return false;
+       }
+
+       fd = aes_ecb_setup(key);
+       if (fd < 0)
+               return false;
+
+       /* C_mic = e(AppKey, 0x01 || nonce || 0x0000) */
+       pmsg[0] = 0x01;
+       memcpy(pmsg + 1, nonce, 13);
+       put_be16(0x0000, pmsg + 14);
+
+       result = aes_ecb(fd, pmsg, cmic);
+       if (!result)
+               goto done;
+
+       /* X_0 = e(AppKey, 0x09 || nonce || length) */
+       if (mic_size == sizeof(uint64_t))
+               pmsg[0] = 0x19 | (aad_len ? 0x40 : 0x00);
+       else
+               pmsg[0] = 0x09 | (aad_len ? 0x40 : 0x00);
+
+       memcpy(pmsg + 1, nonce, 13);
+       put_be16(msg_len, pmsg + 14);
+
+       result = aes_ecb(fd, pmsg, Xn);
+       if (!result)
+               goto done;
+
+       /* If AAD is being used to authenticate, include it here */
+       if (aad_len) {
+               put_be16(aad_len, pmsg);
+
+               for (i = 0; i < sizeof(uint16_t); i++)
+                       pmsg[i] = Xn[i] ^ pmsg[i];
+
+               j = 0;
+               aad_len += sizeof(uint16_t);
+               while (aad_len > 16) {
+                       do {
+                               pmsg[i] = Xn[i] ^ aad[j];
+                               i++, j++;
+                       } while (i < 16);
+
+                       aad_len -= 16;
+                       i = 0;
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+               }
+
+               for (i = 0; i < aad_len; i++, j++)
+                       pmsg[i] = Xn[i] ^ aad[j];
+
+               for (i = aad_len; i < 16; i++)
+                       pmsg[i] = Xn[i];
+
+               result = aes_ecb(fd, pmsg, Xn);
+               if (!result)
+                       goto done;
+       }
+
+       last_blk = msg_len % 16;
+       blk_cnt = (msg_len + 15) / 16;
+       if (!last_blk)
+               last_blk = 16;
+
+       for (j = 0; j < blk_cnt; j++) {
+               if (j + 1 == blk_cnt) {
+                       /* X_1 = e(AppKey, X_0 ^ Payload[0-15]) */
+                       for (i = 0; i < last_blk; i++)
+                               pmsg[i] = Xn[i] ^ msg[(j * 16) + i];
+                       for (i = last_blk; i < 16; i++)
+                               pmsg[i] = Xn[i] ^ 0x00;
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+
+                       /* MIC = C_mic ^ X_1 */
+                       for (i = 0; i < sizeof(mic); i++)
+                               mic[i] = cmic[i] ^ Xn[i];
+
+                       /* C_1 = e(AppKey, 0x01 || nonce || 0x0001) */
+                       pmsg[0] = 0x01;
+                       memcpy(pmsg + 1, nonce, 13);
+                       put_be16(j + 1, pmsg + 14);
+
+                       result = aes_ecb(fd, pmsg, cmsg);
+                       if (!result)
+                               goto done;
+
+                       if (out_msg) {
+                               /* Encrypted = Payload[0-15] ^ C_1 */
+                               for (i = 0; i < last_blk; i++)
+                                       out_msg[(j * 16) + i] =
+                                               msg[(j * 16) + i] ^ cmsg[i];
+
+                       }
+               } else {
+                       /* X_1 = e(AppKey, X_0 ^ Payload[0-15]) */
+                       for (i = 0; i < 16; i++)
+                               pmsg[i] = Xn[i] ^ msg[(j * 16) + i];
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+
+                       /* C_1 = e(AppKey, 0x01 || nonce || 0x0001) */
+                       pmsg[0] = 0x01;
+                       memcpy(pmsg + 1, nonce, 13);
+                       put_be16(j + 1, pmsg + 14);
+
+                       result = aes_ecb(fd, pmsg, cmsg);
+                       if (!result)
+                               goto done;
+
+                       if (out_msg) {
+                               /* Encrypted = Payload[0-15] ^ C_N */
+                               for (i = 0; i < 16; i++)
+                                       out_msg[(j * 16) + i] =
+                                               msg[(j * 16) + i] ^ cmsg[i];
+                       }
+
+               }
+       }
+
+       if (out_msg)
+               memcpy(out_msg + msg_len, mic, mic_size);
+
+       if (out_mic) {
+               switch (mic_size) {
+               case sizeof(uint32_t):
+                       *(uint32_t *)out_mic = get_be32(mic);
+                       break;
+               case sizeof(uint64_t):
+                       *(uint64_t *)out_mic = get_be64(mic);
+                       break;
+               default:
+                       g_printerr("Unsupported MIC size");

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+               }
+       }
+
+done:
+       aes_ecb_destroy(fd);
+
+       return result;
+}
+
+bool mesh_crypto_aes_ccm_decrypt(const uint8_t nonce[13], const

uint8_t key[16],

Quoted 229 lines
mesh/crypto.c new file +229 -0
+                               const uint8_t *aad, uint16_t aad_len,
+                               const uint8_t *enc_msg, uint16_t enc_msg_len,
+                               uint8_t *out_msg, void *out_mic,
+                               size_t mic_size)
+{
+       uint8_t msg[16], pmsg[16], cmic[16], cmsg[16], Xn[16];
+       uint8_t mic[16];
+       uint16_t msg_len = enc_msg_len - mic_size;
+       uint16_t last_blk, blk_cnt;
+       bool result;
+       size_t i, j;
+       int fd;
+
+       if (enc_msg_len < 5 || aad_len >= 0xff00)
+               return false;
+
+       fd = aes_ecb_setup(key);
+       if (fd < 0)
+               return false;
+
+       /* C_mic = e(AppKey, 0x01 || nonce || 0x0000) */
+       pmsg[0] = 0x01;
+       memcpy(pmsg + 1, nonce, 13);
+       put_be16(0x0000, pmsg + 14);
+
+       result = aes_ecb(fd, pmsg, cmic);
+       if (!result)
+               goto done;
+
+       /* X_0 = e(AppKey, 0x09 || nonce || length) */
+       if (mic_size == sizeof(uint64_t))
+               pmsg[0] = 0x19 | (aad_len ? 0x40 : 0x00);
+       else
+               pmsg[0] = 0x09 | (aad_len ? 0x40 : 0x00);
+
+       memcpy(pmsg + 1, nonce, 13);
+       put_be16(msg_len, pmsg + 14);
+
+       result = aes_ecb(fd, pmsg, Xn);
+       if (!result)
+               goto done;
+
+       /* If AAD is being used to authenticate, include it here */
+       if (aad_len) {
+               put_be16(aad_len, pmsg);
+
+               for (i = 0; i < sizeof(uint16_t); i++)
+                       pmsg[i] = Xn[i] ^ pmsg[i];
+
+               j = 0;
+               aad_len += sizeof(uint16_t);
+               while (aad_len > 16) {
+                       do {
+                               pmsg[i] = Xn[i] ^ aad[j];
+                               i++, j++;
+                       } while (i < 16);
+
+                       aad_len -= 16;
+                       i = 0;
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+               }
+
+               for (i = 0; i < aad_len; i++, j++)
+                       pmsg[i] = Xn[i] ^ aad[j];
+
+               for (i = aad_len; i < 16; i++)
+                       pmsg[i] = Xn[i];
+
+               result = aes_ecb(fd, pmsg, Xn);
+               if (!result)
+                       goto done;
+       }
+
+       last_blk = msg_len % 16;
+       blk_cnt = (msg_len + 15) / 16;
+       if (!last_blk)
+               last_blk = 16;
+
+       for (j = 0; j < blk_cnt; j++) {
+               if (j + 1 == blk_cnt) {
+                       /* C_1 = e(AppKey, 0x01 || nonce || 0x0001) */
+                       pmsg[0] = 0x01;
+                       memcpy(pmsg + 1, nonce, 13);
+                       put_be16(j + 1, pmsg + 14);
+
+                       result = aes_ecb(fd, pmsg, cmsg);
+                       if (!result)
+                               goto done;
+
+                       /* Encrypted = Payload[0-15] ^ C_1 */
+                       for (i = 0; i < last_blk; i++)
+                               msg[i] = enc_msg[(j * 16) + i] ^ cmsg[i];
+
+                       if (out_msg)
+                               memcpy(out_msg + (j * 16), msg, last_blk);
+
+                       /* X_1 = e(AppKey, X_0 ^ Payload[0-15]) */
+                       for (i = 0; i < last_blk; i++)
+                               pmsg[i] = Xn[i] ^ msg[i];
+                       for (i = last_blk; i < 16; i++)
+                               pmsg[i] = Xn[i] ^ 0x00;
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+
+                       /* MIC = C_mic ^ X_1 */
+                       for (i = 0; i < sizeof(mic); i++)
+                               mic[i] = cmic[i] ^ Xn[i];
+               } else {
+                       /* C_1 = e(AppKey, 0x01 || nonce || 0x0001) */
+                       pmsg[0] = 0x01;
+                       memcpy(pmsg + 1, nonce, 13);
+                       put_be16(j + 1, pmsg + 14);
+
+                       result = aes_ecb(fd, pmsg, cmsg);
+                       if (!result)
+                               goto done;
+
+                       /* Encrypted = Payload[0-15] ^ C_1 */
+                       for (i = 0; i < 16; i++)
+                               msg[i] = enc_msg[(j * 16) + i] ^ cmsg[i];
+
+                       if (out_msg)
+                               memcpy(out_msg + (j * 16), msg, 16);
+
+                       /* X_1 = e(AppKey, X_0 ^ Payload[0-15]) */
+                       for (i = 0; i < 16; i++)
+                               pmsg[i] = Xn[i] ^ msg[i];
+
+                       result = aes_ecb(fd, pmsg, Xn);
+                       if (!result)
+                               goto done;
+               }
+       }
+
+       switch (mic_size) {
+               case sizeof(uint32_t):
+                       if (out_mic)
+                               *(uint32_t *)out_mic = get_be32(mic);
+                       else if (get_be32(enc_msg + enc_msg_len - mic_size) !=
+                                       get_be32(mic))
+                               result = false;
+                       break;
+
+               case sizeof(uint64_t):
+                       if (out_mic)
+                               *(uint64_t *)out_mic = get_be64(mic);
+                       else if (get_be64(enc_msg + enc_msg_len - mic_size) !=
+                                       get_be64(mic))
+                               result = false;
+                       break;
+
+               default:
+                       g_printerr("Unsupported MIC size");
+                       result = false;
+       }
+
+done:
+       aes_ecb_destroy(fd);
+
+       return result;
+}
+
+bool mesh_crypto_k1(const uint8_t ikm[16], const uint8_t salt[16],
+               const void *info, size_t info_len, uint8_t okm[16])
+{
+       uint8_t res[16];
+
+       if (!aes_cmac_one(salt, ikm, 16, res))
+               return false;
+
+       return aes_cmac_one(res, info, info_len, okm);
+}
+
+bool mesh_crypto_k2(const uint8_t n[16], const uint8_t *p, size_t p_len,
+                                                       uint8_t net_id[1],
+                                                       uint8_t enc_key[16],
+                                                       uint8_t priv_key[16])
+{
+       int fd;
+       uint8_t output[16];
+       uint8_t t[16];
+       uint8_t *stage;
+       bool success = false;
+
+       stage = g_malloc(sizeof(output) + p_len + 1);
+       if (stage == NULL)
+               return false;
+
+       if (!mesh_crypto_s1("smk2", 4, stage))
+               goto fail;
+
+       if (!aes_cmac_one(stage, n, 16, t))
+               goto fail;
+
+       fd = aes_cmac_N_start(t);
+       if (fd < 0)
+               goto fail;
+
+       memcpy(stage, p, p_len);
+       stage[p_len] = 1;
+
+       if(!aes_cmac(fd, stage, p_len + 1, output))
+               goto done;
+
+       net_id[0] = output[15] & 0x7f;
+
+       memcpy(stage, output, 16);
+       memcpy(stage + 16, p, p_len);
+       stage[p_len + 16] = 2;
+
+       if(!aes_cmac(fd, stage, p_len + 16 + 1, output))
+               goto done;
+
+       memcpy(enc_key, output, 16);
+
+       memcpy(stage, output, 16);
+       memcpy(stage + 16, p, p_len);
+       stage[p_len + 16] = 3;
+
+       if(!aes_cmac(fd, stage, p_len + 16 + 1, output))
+               goto done;
+
+       memcpy(priv_key, output, 16);
+       success = true;

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+
+done:
+       aes_cmac_destroy(fd);
+fail:
+       g_free(stage);
+
+       return success;
+}
+
+static bool crypto_128(const uint8_t n[16], const char *s, uint8_t

out128[16])

Quoted 41 lines
mesh/crypto.c new file +41 -0
+{
+       uint8_t id128[] = { 'i', 'd', '1', '2', '8', 0x01 };
+       uint8_t salt[16];
+
+       if (!mesh_crypto_s1(s, 4, salt))
+               return false;
+
+       return mesh_crypto_k1(n, salt, id128, sizeof(id128), out128);
+}
+
+bool mesh_crypto_nkik(const uint8_t n[16], uint8_t identity_key[16])
+{
+       return crypto_128(n, "nkik", identity_key);
+}
+
+static bool identity_calc(const uint8_t net_key[16], uint16_t addr,
+               bool check, uint8_t id[16])
+{
+       uint8_t id_key[16];
+       uint8_t tmp[16];
+
+       if (!mesh_crypto_nkik(net_key, id_key))
+               return false;
+
+       memset(tmp, 0, sizeof(tmp));
+       put_be16(addr, tmp + 14);
+
+       if (check) {
+               memcpy(tmp + 6, id + 8, 8);
+       } else {
+               mesh_get_random_bytes(tmp + 6, 8);
+               memcpy(id + 8, tmp + 6, 8);
+       }
+
+       if (!aes_ecb_one(id_key, tmp, tmp))
+               return false;
+
+       if (check)
+               return (memcmp(id, tmp + 8, 8) == 0);
+
+       memcpy(id, tmp + 8, 8);

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       return true;
+}
+
+bool mesh_crypto_identity(const uint8_t net_key[16], uint16_t addr,
+                                                       uint8_t id[16])
+{
+       return identity_calc(net_key, addr, false, id);
+}
+
+bool mesh_crypto_identity_check(const uint8_t net_key[16], uint16_t

addr,

Quoted 156 lines
mesh/crypto.c new file +156 -0
+                                                       uint8_t id[16])
+{
+       return identity_calc(net_key, addr, true, id);
+}
+
+bool mesh_crypto_nkbk(const uint8_t n[16], uint8_t beacon_key[16])
+{
+       return crypto_128(n, "nkbk", beacon_key);
+}
+
+bool mesh_crypto_k3(const uint8_t n[16], uint8_t out64[8])
+{
+       uint8_t tmp[16];
+       uint8_t t[16];
+       uint8_t id64[] = { 'i', 'd', '6', '4', 0x01 };
+
+       if (!mesh_crypto_s1("smk3", 4, tmp))
+               return false;
+
+       if (!aes_cmac_one(tmp, n, 16, t))
+               return false;
+
+       if (!aes_cmac_one(t, id64, sizeof(id64), tmp))
+               return false;
+
+       memcpy(out64, tmp + 8, 8);
+
+       return true;
+}
+
+bool mesh_crypto_k4(const uint8_t a[16], uint8_t out6[1])
+{
+       uint8_t tmp[16];
+       uint8_t t[16];
+       uint8_t id6[] = { 'i', 'd', '6', 0x01 };
+
+       if (!mesh_crypto_s1("smk4", 4, tmp))
+               return false;
+
+       if (!aes_cmac_one(tmp, a, 16, t))
+               return false;
+
+       if (!aes_cmac_one(t, id6, sizeof(id6), tmp))
+               return false;
+
+       out6[0] = tmp[15] & 0x3f;
+       return true;
+}
+
+bool mesh_crypto_beacon_cmac(const uint8_t encryption_key[16],
+                               const uint8_t network_id[8],
+                               uint32_t iv_index, bool kr, bool iu,
+                               uint64_t *cmac)
+{
+       uint8_t msg[13], tmp[16];
+
+       if (!cmac)
+               return false;
+
+       msg[0] = kr ? 0x01 : 0x00;
+       msg[0] |= iu ? 0x02 : 0x00;
+       memcpy(msg + 1, network_id, 8);
+       put_be32(iv_index, msg + 9);
+
+       if (!aes_cmac_one(encryption_key, msg, 13, tmp))
+               return false;
+
+       *cmac = get_be64(tmp);
+
+       return true;
+}
+
+bool mesh_crypto_network_nonce(bool ctl, uint8_t ttl, uint32_t seq,
+                               uint16_t src, uint32_t iv_index,
+                               uint8_t nonce[13])
+{
+       nonce[0] = 0;
+       nonce[1] = (ttl & TTL_MASK) | (ctl ? CTL : 0x00);
+       nonce[2] = (seq >> 16) & 0xff;
+       nonce[3] = (seq >> 8) & 0xff;
+       nonce[4] = seq & 0xff;
+
+       /* SRC */
+       put_be16(src, nonce + 5);
+
+       put_be16(0, nonce + 7);
+
+       /* IV Index */
+       put_be32(iv_index, nonce + 9);
+
+       return true;
+}
+
+bool mesh_crypto_network_encrypt(bool ctl, uint8_t ttl,
+                               uint32_t seq, uint16_t src,
+                               uint32_t iv_index,
+                               const uint8_t net_key[16],
+                               const uint8_t *enc_msg, uint8_t enc_msg_len,
+                               uint8_t *out, void *net_mic)
+{
+       uint8_t nonce[13];
+
+       if (!mesh_crypto_network_nonce(ctl, ttl, seq, src, iv_index, nonce))
+               return false;
+
+       return mesh_crypto_aes_ccm_encrypt(nonce, net_key,
+                               NULL, 0, enc_msg,
+                               enc_msg_len, out,
+                               net_mic,
+                               ctl ? sizeof(uint64_t) : sizeof(uint32_t));
+}
+
+bool mesh_crypto_network_decrypt(bool ctl, uint8_t ttl,
+                               uint32_t seq, uint16_t src,
+                               uint32_t iv_index,
+                               const uint8_t net_key[16],
+                               const uint8_t *enc_msg, uint8_t enc_msg_len,
+                               uint8_t *out, void *net_mic, size_t mic_size)
+{
+       uint8_t nonce[13];
+
+       if (!mesh_crypto_network_nonce(ctl, ttl, seq, src, iv_index, nonce))
+               return false;
+
+       return mesh_crypto_aes_ccm_decrypt(nonce, net_key, NULL, 0,
+                                               enc_msg, enc_msg_len, out,
+                                               net_mic, mic_size);
+}
+
+bool mesh_crypto_application_nonce(uint32_t seq, uint16_t src,
+                                       uint16_t dst, uint32_t iv_index,
+                                       bool aszmic, uint8_t nonce[13])
+{
+       nonce[0] = 0x01;
+       nonce[1] = aszmic ? 0x80 : 0x00;
+       nonce[2] = (seq & 0x00ff0000) >> 16;
+       nonce[3] = (seq & 0x0000ff00) >> 8;
+       nonce[4] = (seq & 0x000000ff);
+       nonce[5] = (src & 0xff00) >> 8;
+       nonce[6] = (src & 0x00ff);
+       nonce[7] = (dst & 0xff00) >> 8;
+       nonce[8] = (dst & 0x00ff);
+       put_be32(iv_index, nonce + 9);
+
+       return true;
+}
+
+bool mesh_crypto_device_nonce(uint32_t seq, uint16_t src,
+                                       uint16_t dst, uint32_t iv_index,
+                                       bool aszmic, uint8_t nonce[13])
+{
+       nonce[0] = 0x02;
+       nonce[1] = aszmic ? 0x80 : 0x00;
+       nonce[2] = (seq & 0x00ff0000) >> 16;
+       nonce[3] = (seq & 0x0000ff00) >> 8;
+       nonce[4] = (seq & 0x000000ff);

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       nonce[5] = (src & 0xff00) >> 8;
+       nonce[6] = (src & 0x00ff);
+       nonce[7] = (dst & 0xff00) >> 8;
+       nonce[8] = (dst & 0x00ff);
+       put_be32(iv_index, nonce + 9);
+
+       return true;
+}
+
+bool mesh_crypto_application_encrypt(uint8_t key_id, uint32_t seq,

uint16_t src,

Quoted 9 lines
mesh/crypto.c new file +9 -0
+                                       uint16_t dst, uint32_t iv_index,
+                                       const uint8_t app_key[16],
+                                       const uint8_t *aad, uint8_t aad_len,
+                                       const uint8_t *msg, uint8_t msg_len,
+                                       uint8_t *out, void *app_mic,
+                                       size_t mic_size)
+{
+       uint8_t nonce[13];
+       bool aszmic = (mic_size == sizeof(uint64_t)) ? true : false;

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+
+       if (!key_id && !mesh_crypto_device_nonce(seq, src, dst,
+                               iv_index, aszmic, nonce))
+               return false;
+
+       if (key_id && !mesh_crypto_application_nonce(seq, src, dst,
+                               iv_index, aszmic, nonce))
+               return false;
+
+       return mesh_crypto_aes_ccm_encrypt(nonce, app_key, aad,

aad_len,

mesh/crypto.c

Quoted 5 lines
mesh/crypto.c new file +5 -0
+                                               msg, msg_len,
+                                               out, app_mic, mic_size);
+}
+
+bool mesh_crypto_application_decrypt(uint8_t key_id, uint32_t seq,

uint16_t src,

Quoted 142 lines
mesh/crypto.c new file +142 -0
+                               uint16_t dst, uint32_t iv_index,
+                               const uint8_t app_key[16],
+                               const uint8_t *aad, uint8_t aad_len,
+                               const uint8_t *enc_msg, uint8_t enc_msg_len,
+                               uint8_t *out, void *app_mic, size_t mic_size)
+{
+       uint8_t nonce[13];
+       bool aszmic = (mic_size == sizeof(uint64_t)) ? true : false;
+
+       if (!key_id && !mesh_crypto_device_nonce(seq, src, dst,
+                               iv_index, aszmic, nonce))
+               return false;
+
+       if (key_id && !mesh_crypto_application_nonce(seq, src, dst,
+                               iv_index, aszmic, nonce))
+               return false;
+
+       return mesh_crypto_aes_ccm_decrypt(nonce, app_key,
+                                               aad, aad_len, enc_msg,
+                                               enc_msg_len, out,
+                                               app_mic, mic_size);
+}
+
+bool mesh_crypto_session_key(const uint8_t secret[32],
+                                       const uint8_t salt[16],
+                                       uint8_t session_key[16])
+{
+       const uint8_t prsk[4] = "prsk";
+
+       if (!aes_cmac_one(salt, secret, 32, session_key))
+               return false;
+
+       return aes_cmac_one(session_key, prsk, 4, session_key);
+}
+
+bool mesh_crypto_nonce(const uint8_t secret[32],
+                                       const uint8_t salt[16],
+                                       uint8_t nonce[13])
+{
+       const uint8_t prsn[4] = "prsn";
+       uint8_t tmp[16];
+       bool result;
+
+       if (!aes_cmac_one(salt, secret, 32, tmp))
+               return false;
+
+       result =  aes_cmac_one(tmp, prsn, 4, tmp);
+
+       if (result)
+               memcpy(nonce, tmp + 3, 13);
+
+       return result;
+}
+
+bool mesh_crypto_s1(const void *info, size_t len, uint8_t salt[16])
+{
+       const uint8_t zero[16] = {0};
+
+       return aes_cmac_one(zero, info, len, salt);
+}
+
+bool mesh_crypto_prov_prov_salt(const uint8_t conf_salt[16],
+                                       const uint8_t prov_rand[16],
+                                       const uint8_t dev_rand[16],
+                                       uint8_t prov_salt[16])
+{
+       const uint8_t zero[16] = {0};
+       uint8_t tmp[16 * 3];
+
+       memcpy(tmp, conf_salt, 16);
+       memcpy(tmp + 16, prov_rand, 16);
+       memcpy(tmp + 32, dev_rand, 16);
+
+       return aes_cmac_one(zero, tmp, sizeof(tmp), prov_salt);
+}
+
+bool mesh_crypto_prov_conf_key(const uint8_t secret[32],
+                                       const uint8_t salt[16],
+                                       uint8_t conf_key[16])
+{
+       const uint8_t prck[4] = "prck";
+
+       if (!aes_cmac_one(salt, secret, 32, conf_key))
+               return false;
+
+       return aes_cmac_one(conf_key, prck, 4, conf_key);
+}
+
+bool mesh_crypto_device_key(const uint8_t secret[32],
+                                               const uint8_t salt[16],
+                                               uint8_t device_key[16])
+{
+       const uint8_t prdk[4] = "prdk";
+
+       if (!aes_cmac_one(salt, secret, 32, device_key))
+               return false;
+
+       return aes_cmac_one(device_key, prdk, 4, device_key);
+}
+
+bool mesh_crypto_virtual_addr(const uint8_t virtual_label[16],
+                                               uint16_t *addr)
+{
+       uint8_t tmp[16];
+
+       if (!mesh_crypto_s1("vtad", 4, tmp))
+               return false;
+
+       if (!addr || !aes_cmac_one(tmp, virtual_label, 16, tmp))
+               return false;
+
+       *addr = (get_be16(tmp + 14) & 0x3fff) | 0x8000;
+
+       return true;
+}
+
+bool mesh_crypto_packet_encode(uint8_t *packet, uint8_t packet_len,
+                               const uint8_t network_key[16],
+                               uint32_t iv_index,
+                               const uint8_t privacy_key[16])
+{
+       uint8_t network_nonce[13] = { 0x00, 0x00 };
+       uint8_t privacy_counter[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, };
+       uint8_t tmp[16];
+       int i;
+
+       /* Detect Proxy packet by CTL == true && DST == 0x0000 */
+       if ((packet[1] & CTL) && get_be16(packet + 7) == 0)
+               network_nonce[0] = 0x03;
+       else
+               /* CTL + TTL */
+               network_nonce[1] = packet[1];
+
+       /* Seq Num */
+       network_nonce[2] = packet[2];
+       network_nonce[3] = packet[3];
+       network_nonce[4] = packet[4];
+
+       /* SRC */
+       network_nonce[5] = packet[5];
+       network_nonce[6] = packet[6];
+

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       /* DST not available */
+       network_nonce[7] = 0;
+       network_nonce[8] = 0;
+
+       /* IV Index */
+       put_be32(iv_index, network_nonce + 9);
+
+       /* Check for Long net-MIC */
+       if (packet[1] & CTL) {
+               if (!mesh_crypto_aes_ccm_encrypt(network_nonce,

network_key,

mesh/crypto.c

Quoted 6 lines
mesh/crypto.c new file +6 -0
+                                       NULL, 0,
+                                       packet + 7, packet_len - 7 - 8,
+                                       packet + 7, NULL, sizeof(uint64_t)))
+                       return false;
+       } else {
+               if (!mesh_crypto_aes_ccm_encrypt(network_nonce,

network_key,

Quoted 9 lines
mesh/crypto.c new file +9 -0
+                                       NULL, 0,
+                                       packet + 7, packet_len - 7 - 4,
+                                       packet + 7, NULL, sizeof(uint32_t)))
+                       return false;
+       }
+
+       put_be32(iv_index, privacy_counter + 5);
+       memcpy(privacy_counter + 9, packet + 7, 7);
+

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       if (!aes_ecb_one(privacy_key, privacy_counter, tmp))
+               return false;
+
+       for (i = 0; i < 6; i++)
+               packet[1 + i] ^= tmp[i];
+
+       return true;
+}
+
+bool mesh_crypto_packet_decode(const uint8_t *packet, uint8_t

packet_len,

Quoted 47 lines
mesh/crypto.c new file +47 -0
+                               bool proxy, uint8_t *out, uint32_t iv_index,
+                               const uint8_t network_key[16],
+                               const uint8_t privacy_key[16])
+{
+       uint8_t privacy_counter[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, };
+       uint8_t network_nonce[13] = { 0x00, 0x00, };
+       uint8_t tmp[16];
+       uint16_t src;
+       int i;
+
+       if (packet_len < 14)
+               return false;
+
+       put_be32(iv_index, privacy_counter + 5);
+       memcpy(privacy_counter + 9, packet + 7, 7);
+
+       if (!aes_ecb_one(privacy_key, privacy_counter, tmp))
+               return false;
+
+       memcpy(out, packet, packet_len);
+       for (i = 0; i < 6; i++)
+               out[1 + i] ^= tmp[i];
+
+       src  = get_be16(out + 5);
+
+       /* Pre-check SRC address for illegal values */
+       if (!src || src >= 0x8000)
+               return false;
+
+       /* Detect Proxy packet by CTL == true && proxy == true */
+       if ((out[1] & CTL) && proxy)
+               network_nonce[0] = 0x03;
+       else
+               /* CTL + TTL */
+               network_nonce[1] = out[1];
+
+       /* Seq Num */
+       network_nonce[2] = out[2];
+       network_nonce[3] = out[3];
+       network_nonce[4] = out[4];
+
+       /* SRC */
+       network_nonce[5] = out[5];
+       network_nonce[6] = out[6];
+
+       /* DST not available */
+       network_nonce[7] = 0;

mesh/crypto.c

Quoted 10 lines
mesh/crypto.c new file +10 -0
+       network_nonce[8] = 0;
+
+       /* IV Index */
+       put_be32(iv_index, network_nonce + 9);
+
+       /* Check for Long MIC */
+       if (out[1] & CTL) {
+               uint64_t mic;
+
+               if (!mesh_crypto_aes_ccm_decrypt(network_nonce,

network_key,

mesh/crypto.c

Quoted 13 lines
mesh/crypto.c new file +13 -0
+                                       NULL, 0, packet + 7, packet_len - 7,
+                                       out + 7, &mic, sizeof(mic)))
+                       return false;
+
+               mic ^= get_be64(out + packet_len - 8);
+               put_be64(mic, out + packet_len - 8);
+
+               if (mic)
+                       return false;
+       } else {
+               uint32_t mic;
+
+               if (!mesh_crypto_aes_ccm_decrypt(network_nonce,

network_key,

Quoted 43 lines
mesh/crypto.c new file +32 -0
+                                       NULL, 0, packet + 7, packet_len - 7,
+                                       out + 7, &mic, sizeof(mic)))
+                       return false;
+
+               mic ^= get_be32(out + packet_len - 4);
+               put_be32(mic, out + packet_len - 4);
+
+               if (mic)
+                       return false;
+       }
+
+       return true;
+}
+
+bool mesh_get_random_bytes(void *buf, size_t num_bytes)
+{
+       ssize_t len;
+       int fd;
+
+       fd = open("/dev/urandom", O_RDONLY);
+       if (fd < 0)
+               return false;
+
+       len = read(fd, buf, num_bytes);
+
+       close(fd);
+
+       if (len < 0)
+               return false;
+
+       return true;
+}
mesh/gatt.c new file +5 -0
new file mode 100644
index 0000000..b981054
@@ -0,0 +1,609 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/gatt.c line 15

Quoted 10 lines
mesh/gatt.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/gatt.c line 20

Quoted 5 lines
mesh/gatt.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 21 lines
mesh/gatt.c new file +21 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/uio.h>
+#include <wordexp.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+
+#include "src/shared/io.h"
+#include "gdbus/gdbus.h"

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+#include "lib/bluetooth.h"
+#include "lib/uuid.h"
+#include "client/display.h"
+#include "node.h"
+#include "util.h"
+#include "gatt.h"
+#include "prov.h"
+#include "net.h"
+
+#define MESH_PROV_DATA_OUT_UUID_STR    "00002adc-0000-1000-

8000-00805f9b34fb"

mesh/gatt.c line 52

Quoted 1 line
mesh/gatt.c new file +1 -0
+#define MESH_PROXY_DATA_OUT_UUID_STR   "00002ade-0000-1000-

8000-00805f9b34fb"

Quoted 51 lines
mesh/gatt.c new file +51 -0
+
+static struct io *write_io;
+static uint16_t write_mtu;
+
+static struct io *notify_io;
+static uint16_t notify_mtu;
+
+struct write_data {
+       GDBusProxy *proxy;
+       void *user_data;
+       struct iovec iov;
+       GDBusReturnFunction cb;
+       uint8_t *gatt_data;
+       uint8_t gatt_len;
+};
+
+struct notify_data {
+       GDBusProxy *proxy;
+       bool enable;
+       GDBusReturnFunction cb;
+       void *user_data;
+};
+
+bool mesh_gatt_is_child(GDBusProxy *proxy, GDBusProxy *parent,
+                       const char *name)
+{
+       DBusMessageIter iter;
+       const char *parent_path;
+
+       if (!parent)
+               return FALSE;
+
+       if (g_dbus_proxy_get_property(proxy, name, &iter) == FALSE)
+               return FALSE;
+
+       dbus_message_iter_get_basic(&iter, &parent_path);
+
+       if (!strcmp(parent_path, g_dbus_proxy_get_path(parent)))
+               return TRUE;
+       else
+               return FALSE;
+}
+
+/* Refactor this once actual MTU is available */
+#define GATT_MTU       23
+
+static void write_data_free(void *user_data)
+{
+       struct write_data *data = user_data;
+
+       g_free(data->gatt_data);

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+       free(data);
+}
+
+static void write_setup(DBusMessageIter *iter, void *user_data)
+{
+       struct write_data *data = user_data;
+       struct iovec *iov = &data->iov;
+       DBusMessageIter array, dict;
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "y",

&array);

Quoted 185 lines
mesh/gatt.c new file +185 -0
+       dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
+                                               &iov->iov_base, iov->iov_len);
+       dbus_message_iter_close_container(iter, &array);
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+                                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                       DBUS_TYPE_STRING_AS_STRING
+                                       DBUS_TYPE_VARIANT_AS_STRING
+                                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+                                       &dict);
+
+       dbus_message_iter_close_container(iter, &dict);
+}
+
+uint16_t mesh_gatt_sar(uint8_t **pkt, uint16_t size)
+{
+       const uint8_t *data = *pkt;
+       uint8_t gatt_hdr = *data++;
+       uint8_t type = gatt_hdr & GATT_TYPE_MASK;
+       static uint8_t gatt_size;
+       static uint8_t gatt_pkt[67];
+
+       print_byte_array("GATT-RX:\t", *pkt, size);
+       if (size < 1) {
+               gatt_pkt[0] = GATT_TYPE_INVALID;
+               /* TODO: Disconnect GATT per last paragraph sec 6.6 */
+               return 0;
+       }
+
+       size--;
+
+       switch (gatt_hdr & GATT_SAR_MASK) {
+       case GATT_SAR_FIRST:
+               gatt_size = 1;
+               gatt_pkt[0] = type;
+               /* TODO: Start Proxy Timeout */
+               /* fall through */
+
+       case GATT_SAR_CONTINUE:
+               if (gatt_pkt[0] != type ||
+                               gatt_size + size > MAX_GATT_SIZE) {
+
+                       /* Invalidate packet and return failure */
+                       gatt_pkt[0] = GATT_TYPE_INVALID;
+                       /* TODO: Disconnect GATT per last paragraph sec 6.6 */
+                       return 0;
+               }
+
+               memcpy(gatt_pkt + gatt_size, data, size);
+               gatt_size += size;
+
+               /* We are good to this point, but incomplete */
+               return 0;
+
+       default:
+       case GATT_SAR_COMPLETE:
+               gatt_size = 1;
+               gatt_pkt[0] = type;
+
+               /* fall through */
+
+       case GATT_SAR_LAST:
+               if (gatt_pkt[0] != type ||
+                               gatt_size + size > MAX_GATT_SIZE) {
+
+                       /* Invalidate packet and return failure */
+                       gatt_pkt[0] = GATT_TYPE_INVALID;
+                       /* Disconnect GATT per last paragraph sec 6.6 */
+                       return 0;
+               }
+
+               memcpy(gatt_pkt + gatt_size, data, size);
+               gatt_size += size;
+               *pkt = gatt_pkt;
+               return gatt_size;
+       }
+}
+
+static bool pipe_write(struct io *io, void *user_data)
+{
+       struct write_data *data = user_data;
+       struct iovec iov[2];
+       uint8_t sar;
+       uint8_t max_len = write_mtu - 4;
+
+       if (data == NULL)
+               return true;
+
+       print_byte_array("GATT-TX:\t", data->gatt_data, data->gatt_len);
+
+       sar = data->gatt_data[0];
+
+       data->iov.iov_base = data->gatt_data + 1;
+       data->iov.iov_len--;
+
+       iov[0].iov_base = &sar;
+       iov[0].iov_len = sizeof(sar);
+
+       while (1) {
+               int err;
+
+               iov[1] = data->iov;
+
+               err = io_send(io, iov, 2);
+               if (err < 0) {
+                       rl_printf("Failed to write: %s\n", strerror(-err));
+                       write_data_free(data);
+                       return false;
+               }
+
+               switch (sar & GATT_SAR_MASK) {
+               case GATT_SAR_FIRST:
+               case GATT_SAR_CONTINUE:
+                       data->gatt_len -= max_len;
+                       data->iov.iov_base = data->iov.iov_base + max_len;
+
+                       sar &= GATT_TYPE_MASK;
+                       if (max_len < data->gatt_len) {
+                               data->iov.iov_len = max_len;
+                               sar |= GATT_SAR_CONTINUE;
+                       } else {
+                               data->iov.iov_len = data->gatt_len;
+                               sar |= GATT_SAR_LAST;
+                       }
+
+                       break;
+
+               default:
+                       if(data->cb)
+                               data->cb(NULL, data->user_data);
+                       write_data_free(data);
+                       return true;
+               }
+       }
+}
+
+static void write_reply(DBusMessage *message, void *user_data)
+{
+       struct write_data *data = user_data;
+       struct write_data *tmp;
+       uint8_t *dptr = data->gatt_data;
+       uint8_t max_len = GATT_MTU - 3;
+       uint8_t max_seg = GATT_MTU - 4;
+       DBusError error;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               rl_printf("Failed to write: %s\n", error.name);
+               dbus_error_free(&error);
+               return;
+       }
+
+       if (data == NULL)
+               return;
+
+       switch (data->gatt_data[0] & GATT_SAR_MASK) {
+               case GATT_SAR_FIRST:
+               case GATT_SAR_CONTINUE:
+                       tmp = g_new0(struct write_data, 1);
+                       if (!data)
+                               return;
+
+                       *tmp = *data;
+                       tmp->gatt_data = g_malloc(data->gatt_len);
+
+                       if (!tmp->gatt_data) {
+                               g_free(tmp);
+                               return;
+                       }
+
+                       tmp->gatt_data[0] = dptr[0];
+                       data = tmp;
+                       memcpy(data->gatt_data + 1, dptr + max_len,
+                                       data->gatt_len - max_seg);
+                       data->gatt_len -= max_seg;
+                       data->gatt_data[0] &= GATT_TYPE_MASK;
+                       data->iov.iov_base = data->gatt_data;
+                       if (max_len < data->gatt_len) {
+                               data->iov.iov_len = max_len;
+                               data->gatt_data[0] |= GATT_SAR_CONTINUE;
+                       } else {
+                               data->iov.iov_len = data->gatt_len;
+                               data->gatt_data[0] |= GATT_SAR_LAST;
+                       }

mesh/gatt.c line 366

Quoted 10 lines
mesh/gatt.c new file +10 -0
+
+                       break;
+
+               default:
+                       if(data->cb)
+                               data->cb(message, data->user_data);
+                       return;
+       }
+
+       if (g_dbus_proxy_method_call(data->proxy, "WriteValue",

write_setup,

Quoted 38 lines
mesh/gatt.c new file +38 -0
+                               write_reply, data, write_data_free) == FALSE) {
+               rl_printf("Failed to write\n");
+               write_data_free(data);
+               return;
+       }
+
+}
+
+static void write_io_destroy(void)
+{
+       io_destroy(write_io);
+       write_io = NULL;
+       write_mtu = 0;
+}
+
+static void notify_io_destroy(void)
+{
+       io_destroy(notify_io);
+       notify_io = NULL;
+       notify_mtu = 0;
+}
+
+static bool pipe_hup(struct io *io, void *user_data)
+{
+       rl_printf("%s closed\n", io == notify_io ? "Notify" : "Write");
+
+       if (io == notify_io)
+               notify_io_destroy();
+       else
+               write_io_destroy();
+
+       return false;
+}
+
+static struct io *pipe_io_new(int fd)
+{
+       struct io *io;
+

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+       io = io_new(fd);
+
+       io_set_close_on_destroy(io, true);
+
+       io_set_disconnect_handler(io, pipe_hup, NULL, NULL);
+
+       return io;
+}
+
+static void acquire_write_reply(DBusMessage *message, void

*user_data)

Quoted 9 lines
mesh/gatt.c new file +9 -0
+{
+       struct write_data *data = user_data;
+       DBusError error;
+       int fd;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               dbus_error_free(&error);

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+               if (g_dbus_proxy_method_call(data->proxy, "WriteValue",
+                               write_setup, write_reply, data,
+                               write_data_free) == FALSE) {
+                       rl_printf("Failed to write\n");
+                       write_data_free(data);
+               }
+               return;
+       }
+
+       if ((dbus_message_get_args(message, NULL, DBUS_TYPE_UNIX_FD,

&fd,

Quoted 124 lines
mesh/gatt.c new file +124 -0
+                                       DBUS_TYPE_UINT16, &write_mtu,
+                                       DBUS_TYPE_INVALID) == false)) {
+               rl_printf("Invalid AcquireWrite response\n");
+               return;
+       }
+
+       rl_printf("AcquireWrite success: fd %d MTU %u\n", fd, write_mtu);
+
+       write_io = pipe_io_new(fd);
+
+       pipe_write(write_io, data);
+}
+
+bool mesh_gatt_write(GDBusProxy *proxy, uint8_t *buf, uint16_t len,
+                       GDBusReturnFunction cb, void *user_data)
+{
+       struct write_data *data;
+       DBusMessageIter iter;
+       uint8_t max_len;
+
+       if (!buf || !len)
+               return false;
+
+       if (len > 69)
+               return false;
+
+       data = g_new0(struct write_data, 1);
+       if (!data)
+               return false;
+
+       max_len = write_mtu ? write_mtu - 3 : GATT_MTU - 3;
+
+       /* TODO: should keep in queue in case we need to cancel write? */
+
+       data->gatt_len = len;
+       data->gatt_data = g_memdup(buf, len);
+       data->gatt_data[0] &= GATT_TYPE_MASK;
+       if (max_len < len) {
+               len = max_len;
+               data->gatt_data[0] |= GATT_SAR_FIRST;
+       }
+       data->iov.iov_base = data->gatt_data;
+       data->iov.iov_len = len;
+       data->proxy = proxy;
+       data->user_data = user_data;
+       data->cb = cb;
+
+       if (write_io)
+               return pipe_write(write_io, data);
+
+       if (g_dbus_proxy_get_property(proxy, "WriteAcquired", &iter)) {
+               if (g_dbus_proxy_method_call(proxy, "AcquireWrite", NULL,
+                               acquire_write_reply, data, NULL) == FALSE) {
+                       rl_printf("Failed to AcquireWrite\n");
+                       write_data_free(data);
+                       return false;
+               }
+       } else {
+               if (g_dbus_proxy_method_call(data->proxy, "WriteValue",
+                               write_setup, write_reply, data,
+                               write_data_free) == FALSE) {
+                       rl_printf("Failed to write\n");
+                       write_data_free(data);
+                       return false;
+               }
+               print_byte_array("GATT-TX: ", buf, len);
+               rl_printf("Attempting to write %s\n",
+                                               g_dbus_proxy_get_path(proxy));
+       }
+
+       return true;
+}
+
+static void notify_reply(DBusMessage *message, void *user_data)
+{
+       struct notify_data *data = user_data;
+       DBusError error;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               rl_printf("Failed to %s notify: %s\n",
+                               data->enable ? "start" : "stop", error.name);
+               dbus_error_free(&error);
+               goto done;
+       }
+
+       rl_printf("Notify %s\n", data->enable ? "started" : "stopped");
+
+done:
+       if (data->cb)
+               data->cb(message, data->user_data);
+
+       g_free(data);
+}
+
+static bool pipe_read(struct io *io, bool prov, void *user_data)
+{
+       struct mesh_node *node = user_data;
+       uint8_t buf[512];
+       uint8_t *res;
+       int fd = io_get_fd(io);
+       ssize_t len;
+
+       if (io != notify_io)
+               return true;
+
+       while ((len = read(fd, buf, sizeof(buf)))) {
+               if (len <= 0)
+                       break;
+
+               res = buf;
+               mesh_gatt_sar(&res, len);
+
+               if (prov)
+                       prov_data_ready(node, res, len);
+               else
+                       net_data_ready(res, len);
+       }
+
+       return true;
+}
+
+static bool pipe_read_prov(struct io *io, void *user_data)

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+{
+       return pipe_read(io, true, user_data);
+}
+
+static bool pipe_read_proxy(struct io *io, void *user_data)
+{
+       return pipe_read(io, false, user_data);
+}
+
+static void acquire_notify_reply(DBusMessage *message, void

*user_data)

Quoted 17 lines
mesh/gatt.c new file +17 -0
+{
+       struct notify_data *data = user_data;
+       DBusMessageIter iter;
+       DBusError error;
+       int fd;
+       const char *uuid;
+
+       dbus_error_init(&error);
+
+       if (dbus_set_error_from_message(&error, message) == TRUE) {
+               dbus_error_free(&error);
+               if (g_dbus_proxy_method_call(data->proxy, "StartNotify", NULL,
+                                       notify_reply, data, NULL) == FALSE) {
+                       rl_printf("Failed to StartNotify\n");
+                       g_free(data);
+               }
+               return;

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+       }
+
+       if (notify_io) {
+               io_destroy(notify_io);
+               notify_io = NULL;
+       }
+
+       notify_mtu = 0;
+
+       if ((dbus_message_get_args(message, NULL, DBUS_TYPE_UNIX_FD,

&fd,

mesh/gatt.c

Quoted 13 lines
mesh/gatt.c new file +13 -0
+                                       DBUS_TYPE_UINT16, &notify_mtu,
+                                       DBUS_TYPE_INVALID) == false)) {
+               if (g_dbus_proxy_method_call(data->proxy, "StartNotify", NULL,
+                                       notify_reply, data, NULL) == FALSE) {
+                       rl_printf("Failed to StartNotify\n");
+                       g_free(data);
+               }
+               return;
+       }
+
+       rl_printf("AcquireNotify success: fd %d MTU %u\n", fd, notify_mtu);
+
+       if (g_dbus_proxy_get_property(data->proxy, "UUID", &iter) ==

FALSE)

Quoted 13 lines
mesh/gatt.c new file +8 -0
+               goto done;
+
+       notify_io = pipe_io_new(fd);
+
+       dbus_message_iter_get_basic(&iter, &uuid);
+
+       if (!bt_uuid_strcmp(uuid, MESH_PROV_DATA_OUT_UUID_STR))
+               io_set_read_handler(notify_io, pipe_read_prov, data-

user_data,

mesh/gatt.c new file +3 -0
+                                                                       NULL);
+       else if (!bt_uuid_strcmp(uuid, MESH_PROXY_DATA_OUT_UUID_STR))
+               io_set_read_handler(notify_io, pipe_read_proxy, data-

user_data,

mesh/gatt.c

Quoted 10 lines
mesh/gatt.c new file +10 -0
+                                                                       NULL);
+
+done:
+       if (data->cb)
+               data->cb(message, data->user_data);
+
+       g_free(data);
+}
+
+bool mesh_gatt_notify(GDBusProxy *proxy, bool enable,

GDBusReturnFunction cb,

Quoted 50 lines
mesh/gatt.c new file +39 -0
+                       void *user_data)
+{
+       struct notify_data *data;
+       DBusMessageIter iter;
+       const char *method;
+
+       data = g_new0(struct notify_data, 1);
+       data->proxy = proxy;
+       data->enable = enable;
+       data->cb = cb;
+       data->user_data = user_data;
+
+       if (enable == TRUE) {
+               if (g_dbus_proxy_get_property(proxy, "NotifyAcquired", &iter)) {
+                       method = "AcquireNotify";
+                       cb = acquire_notify_reply;
+               } else {
+                       method = "StartNotify";
+                       cb = notify_reply;
+               }
+       } else {
+               if (notify_io) {
+                       notify_io_destroy();
+                       if (cb)
+                               cb(NULL, user_data);
+                       return true;
+               } else {
+                       method = "StopNotify";
+                       cb = notify_reply;
+               }
+       }
+
+       if (g_dbus_proxy_method_call(proxy, method, NULL, cb,
+                                       data, NULL) == FALSE) {
+               rl_printf("Failed to %s\n", method);
+               return false;
+       }
+       return true;
+}
mesh/main.c new file +5 -0
new file mode 100644
index 0000000..a347484
@@ -0,0 +1,2269 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2017  Intel Corporation. All rights reserved.

mesh/main.c line 15

Quoted 10 lines
mesh/main.c new file +10 -0
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU

mesh/main.c line 20

Quoted 5 lines
mesh/main.c new file +5 -0
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301

USA

Quoted 45 lines
mesh/main.c new file +45 -0
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+#include <wordexp.h>
+
+#include <inttypes.h>
+#include <ctype.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include "bluetooth/bluetooth.h"
+
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <glib.h>
+
+#include "lib/bluetooth.h"
+#include "lib/uuid.h"
+#include "src/shared/util.h"
+#include "gdbus/gdbus.h"
+#include "monitor/uuid.h"
+#include "client/display.h"
+#include "mesh-net.h"
+#include "gatt.h"
+#include "crypto.h"
+#include "node.h"
+#include "net.h"
+#include "keys.h"
+#include "prov.h"
+#include "util.h"
+#include "agent.h"
+#include "prov-db.h"
+#include "config-model.h"
+#include "onoff-model.h"

mesh/main.c

Quoted 10 lines
mesh/main.c new file +10 -0
+
+/* String display constants */
+#define COLORED_NEW    COLOR_GREEN "NEW" COLOR_OFF
+#define COLORED_CHG    COLOR_YELLOW "CHG" COLOR_OFF
+#define COLORED_DEL    COLOR_RED "DEL" COLOR_OFF
+
+#define PROMPT_ON      COLOR_BLUE "[meshctl]" COLOR_OFF "# "
+#define PROMPT_OFF     "Waiting to connect to bluetoothd..."
+
+#define MESH_PROV_DATA_IN_UUID_STR     "00002adb-0000-1000-8000-

00805f9b34fb"

mesh/main.c line 76

Quoted 1 line
mesh/main.c new file +1 -0
+#define MESH_PROV_DATA_OUT_UUID_STR    "00002adc-0000-1000-

8000-00805f9b34fb"

mesh/main.c line 77

Quoted 1 line
mesh/main.c new file +1 -0
+#define MESH_PROXY_DATA_IN_UUID_STR    "00002add-0000-1000-8000-

00805f9b34fb"

mesh/main.c line 78

Quoted 1 line
mesh/main.c new file +1 -0
+#define MESH_PROXY_DATA_OUT_UUID_STR   "00002ade-0000-1000-

8000-00805f9b34fb"

Quoted 102 lines
mesh/main.c new file +102 -0
+
+static GMainLoop *main_loop;
+static DBusConnection *dbus_conn;
+
+struct adapter {
+GDBusProxy *proxy;
+       GList *mesh_devices;
+};
+
+struct mesh_device {
+       GDBusProxy *proxy;
+       uint8_t dev_uuid[16];
+       gboolean hide;
+};
+
+GList *service_list;
+GList *char_list;
+
+static GList *ctrl_list;
+static struct adapter *default_ctrl;
+
+static char *mesh_prov_db_filename;
+static char *mesh_local_config_filename;
+
+static bool discovering = false;
+static bool discover_mesh;
+static uint16_t prov_net_key_index = NET_IDX_PRIMARY;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mesh/main.c line 115

Quoted 10 lines
mesh/main.c new file +10 -0
+
+static guint input = 0;
+
+#define CONN_TYPE_NETWORK      0x00
+#define CONN_TYPE_IDENTITY     0x01
+#define CONN_TYPE_PROVISION    0x02
+#define CONN_TYPE_INVALID      0xff
+
+#define NET_IDX_INVALID                0xffff
+
[… more lines in the raw message]

condition,

mesh/main.c

Quoted 32 lines
mesh/main.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 8 lines
mesh/main.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 158 lines
mesh/main.c new file +158 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uuid[16])

mesh/main.c

Quoted 31 lines
mesh/main.c new file +31 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

len,

mesh/main.c

Quoted 18 lines
mesh/main.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

len,

mesh/main.c

Quoted 42 lines
mesh/main.c new file +42 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

connection.net_idx)

mesh/main.c

Quoted 14 lines
mesh/main.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*target_uuid,

mesh/main.c

Quoted 36 lines
mesh/main.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DBUS_TYPE_VARIANT)

mesh/main.c

Quoted 5 lines
mesh/main.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DBUS_TYPE_ARRAY)

mesh/main.c

Quoted 5 lines
mesh/main.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DBUS_TYPE_BYTE)

mesh/main.c

Quoted 3 lines
mesh/main.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&len);

mesh/main.c

Quoted 29 lines
mesh/main.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DBUS_TYPE_STRING) {

mesh/main.c

Quoted 31 lines
mesh/main.c new file +31 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*master)

mesh/main.c

Quoted 62 lines
mesh/main.c new file +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

desc,

mesh/main.c

Quoted 51 lines
mesh/main.c new file +51 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

{

mesh/main.c

Quoted 32 lines
mesh/main.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mesh_devices,

mesh/main.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

mesh/main.c

Quoted 65 lines
mesh/main.c new file +65 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

user_data,

mesh/main.c

Quoted 47 lines
mesh/main.c new file +47 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 57 lines
mesh/main.c new file +57 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 32 lines
mesh/main.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*char_uuid)

mesh/main.c

Quoted 62 lines
mesh/main.c new file +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

notify_proxy_out_cb);

mesh/main.c

Quoted 38 lines
mesh/main.c new file +38 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 145 lines
mesh/main.c new file +45 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mesh_devices,

mesh/main.c new file +99 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MESH_PROV_DATA_OUT_UUID_STR);

mesh/main.c

Quoted 2 lines
mesh/main.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MESH_PROXY_DATA_OUT_UUID_STR))

mesh/main.c

Quoted 114 lines
mesh/main.c new file +114 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dbus_message_get_interface(message),

mesh/main.c

Quoted 4 lines
mesh/main.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*address)

mesh/main.c

Quoted 22 lines
mesh/main.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*value)

mesh/main.c

Quoted 116 lines
mesh/main.c new file +116 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

"Powered",

mesh/main.c

Quoted 39 lines
mesh/main.c new file +39 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&value);

mesh/main.c

Quoted 7 lines
mesh/main.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*val,

mesh/main.c

Quoted 16 lines
mesh/main.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DBUS_TYPE_OBJECT_PATH) {

mesh/main.c

Quoted 29 lines
mesh/main.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&key);

mesh/main.c

Quoted 7 lines
mesh/main.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

key_type,

mesh/main.c

Quoted 16 lines
mesh/main.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

type,

mesh/main.c

Quoted 18 lines
mesh/main.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 33 lines
mesh/main.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uuids,

mesh/main.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 34 lines
mesh/main.c new file +34 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

"SetDiscoveryFilter",

mesh/main.c

Quoted 118 lines
mesh/main.c new file +118 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_data)

mesh/main.c

Quoted 54 lines
mesh/main.c new file +54 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

node_find_by_uuid(connection.dev_uuid);

mesh/main.c

Quoted 57 lines
mesh/main.c new file +57 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

"unprovision" */

mesh/main.c

Quoted 23 lines
mesh/main.c new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

connect_reply,

mesh/main.c

Quoted 71 lines
mesh/main.c new file +71 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

network"},

Quoted 1 line

+ { "discover-unprovisioned", "<on/off>",

cmd_scan_unprovisioned_devices,

mesh/main.c

Quoted 52 lines
mesh/main.c new file +52 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

condition,

mesh/main.c

Quoted 149 lines
mesh/main.c new file +149 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

strlen("local_node.json")

mesh/main.c

Quoted 5 lines
mesh/main.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

2);

mesh/main.c

Quoted 27 lines
mesh/main.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

strlen("prov_db.json"),

mesh/main.c

Quoted 24 lines
mesh/main.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

NULL);

mesh/main.c

Quoted 3 lines
mesh/main.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

proxy_removed,

mesh/net.c

Quoted 59 lines
mesh/main.c new file +38 -0

Lines of this file are not shown. View the raw message.

mesh/net.c new file +15 -0
new file mode 100644
index 0000000..fb2d200

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/net.c

Quoted 5 lines
mesh/net.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/net.c

Quoted 150 lines
mesh/net.c new file +150 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

while(0)

mesh/net.c

Quoted 2 lines
mesh/net.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

while(0)

mesh/net.c

Quoted 2 lines
mesh/net.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0))

mesh/net.c

Quoted 4 lines
mesh/net.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x8003) \

mesh/net.c

Quoted 6 lines
mesh/net.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

while(0)

mesh/net.c

Quoted 9 lines
mesh/net.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

while(0)

mesh/net.c

Quoted 2 lines
mesh/net.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

while(0)

mesh/net.c

Quoted 2 lines
mesh/net.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0))

mesh/net.c

Quoted 2 lines
mesh/net.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x8003) \

mesh/net.c

Quoted 65 lines
mesh/net.c new file +65 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

find_net_key_by_id(proxy_beacon);

mesh/net.c

Quoted 117 lines
mesh/net.c new file +117 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*key,

mesh/net.c

Quoted 5 lines
mesh/net.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(app_idx),

mesh/net.c

Quoted 48 lines
mesh/net.c new file +48 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(net_idx),

mesh/net.c

Quoted 308 lines
mesh/net.c new file +308 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(num_eles),

mesh/net.c

Quoted 344 lines
mesh/net.c new file +326 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

net_id,

mesh/net.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

iv_index);

mesh/net.c

Quoted 45 lines
mesh/net.c new file +45 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

iv_index,

mesh/net.c

Quoted 760 lines
mesh/net.c new file +385 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

va16)

mesh/net.c new file +374 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

NET_OP_SEG_ACKNOWLEDGE) {

mesh/net.c

Quoted 101 lines
mesh/net.c new file +101 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

find_app_key_by_idx(app_idx);

mesh/net.c

Quoted 148 lines
mesh/net.c new file +148 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ACKing)

mesh/node.c

Quoted 67 lines
mesh/net.c new file +46 -0

Lines of this file are not shown. View the raw message.

mesh/node.c new file +15 -0
new file mode 100644
index 0000000..ba8d4b6

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/node.c

Quoted 5 lines
mesh/node.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/node.c

Quoted 250 lines
mesh/node.c new file +250 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(index));

mesh/node.c

Quoted 13 lines
mesh/node.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(index));

mesh/node.c

Quoted 72 lines
mesh/node.c new file +72 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

num_ele)

mesh/node.c

Quoted 26 lines
mesh/node.c new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uint16_t len)

mesh/node.c

Quoted 97 lines
mesh/node.c new file +97 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

src,

mesh/node.c

Quoted 134 lines
mesh/node.c new file +134 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

user_data);

mesh/node.c

Quoted 3 lines
mesh/node.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

model_id,

mesh/node.c

Quoted 10 lines
mesh/node.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(ele_idx),

mesh/node.c

Quoted 39 lines
mesh/node.c new file +39 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(ele_idx),

mesh/node.c

Quoted 15 lines
mesh/node.c new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uint32_t id)

mesh/node.c

Quoted 9 lines
mesh/node.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(ele_idx),

mesh/node.c

Quoted 36 lines
mesh/node.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mesh_node *node)

mesh/node.c

Quoted 8 lines
mesh/node.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ele_idx,

mesh/node.c

Quoted 9 lines
mesh/node.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GUINT_TO_POINTER(ele_idx),

mesh/node.c

Quoted 64 lines
mesh/node.c new file +64 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

seq)

mesh/node.c

Quoted 43 lines
mesh/node.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uint32_t model_id,

mesh/node.c

Quoted 21 lines
mesh/node.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*node, uint8_t ele,

mesh/onoff-model.c

Quoted 31 lines
mesh/node.c new file +10 -0

Lines of this file are not shown. View the raw message.

mesh/onoff-model.c new file +15 -0
new file mode 100644
index 0000000..61c6ed6

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/onoff-model.c

Quoted 5 lines
mesh/onoff-model.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/onoff-model.c

Quoted 84 lines
mesh/onoff-model.c new file +84 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

msecs\n",

mesh/onoff-model.c

Quoted 195 lines
mesh/onoff-model.c new file +195 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GENERIC_ONOFF_CLIENT_MODEL_ID,

mesh/prov-db.c

Quoted 28 lines
mesh/onoff-model.c new file +7 -0

Lines of this file are not shown. View the raw message.

mesh/prov-db.c new file +15 -0
new file mode 100644
index 0000000..aad6145

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/prov-db.c

Quoted 5 lines
mesh/prov-db.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/prov-db.c

Quoted 98 lines
mesh/prov-db.c new file +98 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

value)

mesh/prov-db.c

Quoted 10 lines
mesh/prov-db.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

value)

mesh/prov-db.c

Quoted 114 lines
mesh/prov-db.c new file +114 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

index,

mesh/prov-db.c

Quoted 133 lines
mesh/prov-db.c new file +133 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ele_idx,

mesh/prov-db.c

Quoted 113 lines
mesh/prov-db.c new file +113 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

primary)

mesh/prov-db.c

Quoted 103 lines
mesh/prov-db.c new file +103 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*data,

mesh/prov-db.c

Quoted 173 lines
mesh/prov-db.c new file +173 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

update)

mesh/prov-db.c

Quoted 14 lines
mesh/prov-db.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

prov)

mesh/prov-db.c

Quoted 83 lines
mesh/prov-db.c new file +83 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uint32_t seq)

mesh/prov-db.c

Quoted 45 lines
mesh/prov-db.c new file +45 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

char *desc)

mesh/prov-db.c

Quoted 55 lines
mesh/prov-db.c new file +55 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ele_idx,

mesh/prov-db.c

Quoted 111 lines
mesh/prov-db.c new file +111 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ele_idx,

mesh/prov-db.c

Quoted 123 lines
mesh/prov-db.c new file +123 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

json_object *jcomp)

mesh/prov-db.c

Quoted 193 lines
mesh/prov-db.c new file +193 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

local)

mesh/prov.c

Quoted 232 lines
mesh/prov-db.c new file +211 -0

Lines of this file are not shown. View the raw message.

mesh/prov.c new file +15 -0
new file mode 100644
index 0000000..89fc884

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/prov.c

Quoted 5 lines
mesh/prov.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/prov.c

Quoted 143 lines
mesh/prov.c new file +143 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

uint16_t net_idx,

mesh/prov.c

Quoted 261 lines
mesh/prov.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_key);

mesh/prov.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_key));

mesh/prov.c new file +219 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

node);

mesh/prov.c

Quoted 5 lines
mesh/prov.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

len)

mesh/prov.c

Quoted 204 lines
mesh/prov.c new file +204 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

mesh/util.c

Quoted 55 lines
mesh/prov.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

conf_in.caps.num_ele);

mesh/prov.c new file +17 -0

Lines of this file are not shown. View the raw message.

mesh/util.c new file +15 -0
new file mode 100644
index 0000000..cb241b3

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GNU

mesh/util.c

Quoted 5 lines
mesh/util.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

USA

mesh/util.c

Quoted 76 lines
mesh/util.c new file +76 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*cmd_table)

mesh/util.c

Quoted 27 lines
mesh/util.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

name,

mesh/util.c

Quoted 156 lines
mesh/util.c new file +156 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*opcode, int *n)

mesh/util.c

Quoted 49 lines
mesh/util.c new file +49 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Resources";

mesh/util.c

Quoted 1 line
mesh/util.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Stored";

mesh/util.c

Quoted 1 line
mesh/util.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Parameters";

mesh/util.c

Quoted 1 line
mesh/util.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Model";

mesh/util.c

Quoted 2 lines
mesh/util.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Supported";

mesh/util.c

Quoted 4 lines
mesh/util.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

change state";

mesh/util.c

Quoted 2 lines
mesh/util.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

error";

Quoted 31 lines
mesh/util.c new file +30 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 2 lines

2.9.5

--
Luiz Augusto von Dentz

Signature · 1 line
Luiz Augusto von Dentz

Part of the diff is not shown here. View the raw message.

author
#8 lore raw

PATCH 5/5 mesh: Add mesh to main bluez build

In reply to Brian Gix
---
 Makefile.tools      | 24 ++++++++++++++++++++++++
 bootstrap-configure |  1 +
 configure.ac        | 18 ++++++++++++++++++
 3 files changed, 43 insertions(+)
Makefile.tools +24 -0
index 0fd6dec..f646bb7 100644
@@ -13,6 +13,30 @@ client_bluetoothctl_LDADD = gdbus/libgdbus-internal.la src/libshared-glib.la \
 				@GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 endif
 
+if BTMESH
+bin_PROGRAMS += mesh/meshctl
+
+mesh_meshctl_SOURCES = mesh/main.c \
+					mesh/node.h mesh/node.c \
+					mesh/gatt.h mesh/gatt.c \
+					mesh/crypto.h mesh/crypto.c \
+					mesh/keys.h \
+					mesh/net.h mesh/net.c \
+					mesh/prov.h mesh/prov.c \
+					mesh/util.h mesh/util.c \
+					mesh/agent.h mesh/agent.c \
+					mesh/prov-db.h mesh/prov-db.c \
+					mesh/config-model.h mesh/config-client.c \
+					mesh/config-server.c \
+					mesh/onoff-model.h mesh/onoff-model.c \
+					client/display.h client/display.c \
+					monitor/uuid.h monitor/uuid.c
+mesh_meshctl_LDADD = lib/libbluetooth-internal.la gdbus/libgdbus-internal.la \
+					src/libshared-glib.la \
+					@GLIB_LIBS@ @DBUS_LIBS@ -ljson-c -lreadline
+endif
+
+
 if MONITOR
 bin_PROGRAMS += monitor/btmon
 
bootstrap-configure +1 -0
index 47926fc..658eef2 100755
@@ -23,4 +23,5 @@ fi
 		--enable-android \
 		--enable-sixaxis \
 		--enable-midi \
+		--enable-mesh \
 		--disable-datafiles $*
configure.ac +18 -0
index 89b164b..bbbc760 100644
@@ -331,6 +331,24 @@ AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
 			[Directory for the configuration files])
 AC_SUBST(CONFIGDIR, "${configdir}")
 
+AC_ARG_ENABLE(mesh, AC_HELP_STRING([--enable-mesh],
+			[enable BlueZ for Bluetooth Mesh]),
+					[enable_mesh=${enableval}])
+AM_CONDITIONAL(BTMESH, test "${enable_mesh}" = "yes")
+
+if (test "${enable_mesh}" == "yes"); then
+	PKG_CHECK_MODULES(JSONC, json-c, dummy=yes,
+				AC_MSG_ERROR(json-c is required))
+	AC_SUBST(JSON_CFLAGS)
+	AC_SUBST(JSON_LIBS)
+fi
+
+if (test "${enable_mesh}" == "yes"); then
+	AC_CHECK_HEADERS(readline/readline.h, enable_readline=yes,
+                AC_MSG_ERROR(readline header files are required))
+fi
+AM_CONDITIONAL(READLINE, test "${enable_readline}" = "yes")
+
 AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
 			[enable BlueZ for Android]),
 					[enable_android=${enableval}])
Signature · 1 line
2.9.5
#9 lore raw
In reply to Brian Gix

Hi Brian,

Quoted 63 lines · On Monday, 14 August 2017 21:01:14 CEST Brian Gix wrote:

With the recent adoption of the Bluetooth Mesh Profile, we offer this GATT Client provisioner tool (meshctl).

Brian Gix / Inga Stotland` (5):
mesh: Add BT SIG reserved numbers for Mesh
mesh: define APIs for Bluetooth Mesh
mesh: Baseline Mesh runtime configuration files
mesh: Baseline Mesh implementation
mesh: Add mesh to main bluez build

 Makefile.tools       |   24 +
 bootstrap-configure  |    1 +
 configure.ac         |   18 +
 lib/uuid.h           |   10 +
 mesh/README          |   26 +
 mesh/agent.c         |  276 ++++++
 mesh/agent.h         |   58 ++
 mesh/config-client.c |  667 +++++++++++++++
 mesh/config-model.h  |  119 +++
 mesh/config-server.c |  165 ++++
 mesh/crypto.c        | 1168 ++++++++++++++++++++++++++
 mesh/crypto.h        |  133 +++
 mesh/gatt.c          |  609 ++++++++++++++
 mesh/gatt.h          |   47 ++
 mesh/keys.h          |   43 +
 mesh/local_node.json |   61 ++
 mesh/main.c          | 2269
++++++++++++++++++++++++++++++++++++++++++++++++++ mesh/mesh-net.h      | 
174 ++++
 mesh/net.c           | 2184
++++++++++++++++++++++++++++++++++++++++++++++++ mesh/net.h           |  
72 ++
 mesh/node.c          |  879 +++++++++++++++++++
 mesh/node.h          |  146 ++++
 mesh/onoff-model.c   |  306 +++++++
 mesh/onoff-model.h   |   50 ++
 mesh/prov-db.c       | 1599 +++++++++++++++++++++++++++++++++++
 mesh/prov-db.h       |   52 ++
 mesh/prov.c          |  664 +++++++++++++++
 mesh/prov.h          |   43 +
 mesh/prov_db.json    |   37 +
 mesh/util.c          |  369 ++++++++
 mesh/util.h          |   71 ++
 31 files changed, 12340 insertions(+)
 create mode 100644 mesh/README
 create mode 100644 mesh/agent.c
 create mode 100644 mesh/agent.h
 create mode 100644 mesh/config-client.c
 create mode 100644 mesh/config-model.h
 create mode 100644 mesh/config-server.c
 create mode 100644 mesh/crypto.c
 create mode 100644 mesh/crypto.h
 create mode 100644 mesh/gatt.c
 create mode 100644 mesh/gatt.h
 create mode 100644 mesh/keys.h
 create mode 100644 mesh/local_node.json
 create mode 100644 mesh/main.c
 create mode 100644 mesh/mesh-net.h
 create mode 100644 mesh/net.c
 create mode 100644 mesh/net.h
 create mode 100644 mesh/node.c
 create mode 100644 mesh/node.h
 create mode 100644 mesh/onoff-model.c
Quoted 8 lines
 create mode 100644 mesh/onoff-model.h
 create mode 100644 mesh/prov-db.c
 create mode 100644 mesh/prov-db.h
 create mode 100644 mesh/prov.c
 create mode 100644 mesh/prov.h
 create mode 100644 mesh/prov_db.json
 create mode 100644 mesh/util.c
 create mode 100644 mesh/util.h

Seems like 4th patch didn't make it to the list. Looking at code size it seems like it is too big and was rejected by vger. Would it be possible to upload this code eg to gihub?

Signature · 2 lines
pozdrawiam
Szymon Janc
#10 lore raw

Hi Szymon,

Quoted 75 lines · Szymon Janc

Hi Brian,

Quoted 63 lines · On Monday, 14 August 2017 21:01:14 CEST Brian Gix wrote:

With the recent adoption of the Bluetooth Mesh Profile, we offer this GATT Client provisioner tool (meshctl).

Brian Gix / Inga Stotland` (5):
mesh: Add BT SIG reserved numbers for Mesh
mesh: define APIs for Bluetooth Mesh
mesh: Baseline Mesh runtime configuration files
mesh: Baseline Mesh implementation
mesh: Add mesh to main bluez build

 Makefile.tools       |   24 +
 bootstrap-configure  |    1 +
 configure.ac         |   18 +
 lib/uuid.h           |   10 +
 mesh/README          |   26 +
 mesh/agent.c         |  276 ++++++
 mesh/agent.h         |   58 ++
 mesh/config-client.c |  667 +++++++++++++++
 mesh/config-model.h  |  119 +++
 mesh/config-server.c |  165 ++++
 mesh/crypto.c        | 1168 ++++++++++++++++++++++++++
 mesh/crypto.h        |  133 +++
 mesh/gatt.c          |  609 ++++++++++++++
 mesh/gatt.h          |   47 ++
 mesh/keys.h          |   43 +
 mesh/local_node.json |   61 ++
 mesh/main.c          | 2269
++++++++++++++++++++++++++++++++++++++++++++++++++ mesh/mesh-net.h      |
174 ++++
 mesh/net.c           | 2184
++++++++++++++++++++++++++++++++++++++++++++++++ mesh/net.h           |
72 ++
 mesh/node.c          |  879 +++++++++++++++++++
 mesh/node.h          |  146 ++++
 mesh/onoff-model.c   |  306 +++++++
 mesh/onoff-model.h   |   50 ++
 mesh/prov-db.c       | 1599 +++++++++++++++++++++++++++++++++++
 mesh/prov-db.h       |   52 ++
 mesh/prov.c          |  664 +++++++++++++++
 mesh/prov.h          |   43 +
 mesh/prov_db.json    |   37 +
 mesh/util.c          |  369 ++++++++
 mesh/util.h          |   71 ++
 31 files changed, 12340 insertions(+)
 create mode 100644 mesh/README
 create mode 100644 mesh/agent.c
 create mode 100644 mesh/agent.h
 create mode 100644 mesh/config-client.c
 create mode 100644 mesh/config-model.h
 create mode 100644 mesh/config-server.c
 create mode 100644 mesh/crypto.c
 create mode 100644 mesh/crypto.h
 create mode 100644 mesh/gatt.c
 create mode 100644 mesh/gatt.h
 create mode 100644 mesh/keys.h
 create mode 100644 mesh/local_node.json
 create mode 100644 mesh/main.c
 create mode 100644 mesh/mesh-net.h
 create mode 100644 mesh/net.c
 create mode 100644 mesh/net.h
 create mode 100644 mesh/node.c
 create mode 100644 mesh/node.h
 create mode 100644 mesh/onoff-model.c
Quoted 8 lines
 create mode 100644 mesh/onoff-model.h
 create mode 100644 mesh/prov-db.c
 create mode 100644 mesh/prov-db.h
 create mode 100644 mesh/prov.c
 create mode 100644 mesh/prov.h
 create mode 100644 mesh/prov_db.json
 create mode 100644 mesh/util.c
 create mode 100644 mesh/util.h
Quoted 3 lines

Seems like 4th patch didn't make it to the list. Looking at code size it seems like it is too big and was rejected by vger. Would it be possible to upload this code eg to gihub?

Or CC you as well.

Signature · 1 line
Luiz Augusto von Dentz
maintainer
#11 lore raw
In reply to Brian Gix

Hi Brian,

Quoted 61 lines

With the recent adoption of the Bluetooth Mesh Profile, we offer this GATT Client provisioner tool (meshctl).

Brian Gix / Inga Stotland` (5):
mesh: Add BT SIG reserved numbers for Mesh
mesh: define APIs for Bluetooth Mesh
mesh: Baseline Mesh runtime configuration files
mesh: Baseline Mesh implementation
mesh: Add mesh to main bluez build

Makefile.tools       |   24 +
bootstrap-configure  |    1 +
configure.ac         |   18 +
lib/uuid.h           |   10 +
mesh/README          |   26 +
mesh/agent.c         |  276 ++++++
mesh/agent.h         |   58 ++
mesh/config-client.c |  667 +++++++++++++++
mesh/config-model.h  |  119 +++
mesh/config-server.c |  165 ++++
mesh/crypto.c        | 1168 ++++++++++++++++++++++++++
mesh/crypto.h        |  133 +++
mesh/gatt.c          |  609 ++++++++++++++
mesh/gatt.h          |   47 ++
mesh/keys.h          |   43 +
mesh/local_node.json |   61 ++
mesh/main.c          | 2269 ++++++++++++++++++++++++++++++++++++++++++++++++++
mesh/mesh-net.h      |  174 ++++
mesh/net.c           | 2184 ++++++++++++++++++++++++++++++++++++++++++++++++
mesh/net.h           |   72 ++
mesh/node.c          |  879 +++++++++++++++++++
mesh/node.h          |  146 ++++
mesh/onoff-model.c   |  306 +++++++
mesh/onoff-model.h   |   50 ++
mesh/prov-db.c       | 1599 +++++++++++++++++++++++++++++++++++
mesh/prov-db.h       |   52 ++
mesh/prov.c          |  664 +++++++++++++++
mesh/prov.h          |   43 +
mesh/prov_db.json    |   37 +
mesh/util.c          |  369 ++++++++
mesh/util.h          |   71 ++
31 files changed, 12340 insertions(+)

create mode 100644 mesh/README create mode 100644 mesh/agent.c create mode 100644 mesh/agent.h create mode 100644 mesh/config-client.c create mode 100644 mesh/config-model.h create mode 100644 mesh/config-server.c create mode 100644 mesh/crypto.c create mode 100644 mesh/crypto.h create mode 100644 mesh/gatt.c create mode 100644 mesh/gatt.h create mode 100644 mesh/keys.h create mode 100644 mesh/local_node.json create mode 100644 mesh/main.c create mode 100644 mesh/mesh-net.h create mode 100644 mesh/net.c create mode 100644 mesh/net.h create mode 100644 mesh/node.c create mode 100644 mesh/node.h create mode 100644 mesh/onoff-model.c

Quoted 8 lines

create mode 100644 mesh/onoff-model.h create mode 100644 mesh/prov-db.c create mode 100644 mesh/prov-db.h create mode 100644 mesh/prov.c create mode 100644 mesh/prov.h create mode 100644 mesh/prov_db.json create mode 100644 mesh/util.c create mode 100644 mesh/util.h

all 5 patches have been applied.

Regards

Marcel