Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wirepas Interoperability #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/provisioning/provisioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ provisioning_res_e process_data_packet(void)
}
}

else if (m_conf.method == PROV_METHOD_SECURED)
else if (m_conf.method == PROV_METHOD_SECURED || m_conf.method == PROV_METHOD_EXTENDED_UID)
{
if (pdu->data.key_index == 1)
{
Expand Down
1 change: 1 addition & 0 deletions libraries/provisioning/provisioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef enum
{
PROV_METHOD_UNSECURED = 0, /**< Unsecured provisioning method. */
PROV_METHOD_SECURED = 1, /**< Secured provisioning method. */
PROV_METHOD_EXTENDED_UID = 3 /**< Extended UID provisioning method. */
} provisioning_method_e;

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/provisioning/provisioning_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
#define PROV_DATA_MAX_USER_ID 255

/** Network address for sending and receiving joining beacons */
#define JOINING_NETWORK_ADDRESS 0x89d3b8 // "JBTX"
#define JOINING_NETWORK_ADDRESS 0x9E4ADC // "JBTX"

/** Network channel for sending and receiving joining beacons */
#define JOINING_NETWORK_CHANNEL 4
#define JOINING_NETWORK_CHANNEL 36

/** Time to scan for joining beacons, in milliseconds.
* \ref JOINING_RX_TIMEOUT and \ref JOINING_TX_INTERVAL needs to
Expand Down
20 changes: 15 additions & 5 deletions source/unitary_apps/provisioning_joining_node/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# This is an example file to customize a node running the provisioning joining node appliation
# using the ExtendedUID method.

# Hex array must start with 0x otherwise it is treated as a string.

# Format is:
#
# provisioning :
# uid : Ex: test_node
# factory_key : (32 bytes string, [0:15 Auth key][16:31 Enc Key]) Needed for sercured method.
# method : (Unsecured:0 or Secured:1) Ex: 0
# device_uid: (16 bytes string, Representing the UID of the device to be provisioned)
# device_uid_type: (1 byte string, Representing the UID type of device_uid)
# authenticator_uid: (16 bytes string, Representing the UID of the authenticator)
# authenticator_uid_type: (1 byte string, Representing the UID type of authenticator_uid)
# Instead of specifying uid components individually, you can specify the whole uid as follows:
# uid: (34 bytes string, [0:1 device_uid_type][1:16 device_uid][16:17 authenticator_uid_type][17:33 authenticator_uid])
# factory_key : (32 bytes string, [0:15 Auth key][16:31 Enc Key]) Needed for secured method.
# method : (Unsecured:0, Secured:1, Extended:3) Ex: 0

provisioning:
uid: test_node
uid: 0x01 0xb3 0x43 0x33 0x00 0x93 0x81 0x08 0x4a 0x8d 0xb3 0xaa 0x9e 0x53 0xd2 0x2a 0x1e 0x01 0x7e 0x71 0xe5 0xd7 0x22 0xef 0x0f 0x4b 0xa8 0x7d 0x44 0xd4 0xe0 0xe5 0xb5 0x7d
node_uid: 0x7e 0x71 0xe5 0xd7 0x22 0xef 0x0f 0x4b 0xa8 0x7d 0x44 0xd4 0xe0 0xe5 0xb5 0x7d
node_uid_type: 0x01
authenticator_uid: 0xb3 0x43 0x33 0x00 0x93 0x81 0x08 0x4a 0x8d 0xb3 0xaa 0x9e 0x53 0xd2 0x2a 0x1e
authenticator_uid_type: 0x01
factory_key : 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0X09 0X0A 0X0B 0X0C 0X0D 0X0E 0X0F 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0X09 0X0A 0X0B 0X0C 0X0D 0X0E 0X0F
method: 1
method: 0x03
14 changes: 14 additions & 0 deletions source/unitary_apps/provisioning_joining_node/config_insecure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is an example file to customize a node running the provisioning joining node appliation
# using the insecure method.

# Hex array must start with 0x otherwise it is treated as a string.

# Format is:
#
# provisioning :
# uid: (bytes string, less than 79 bytes long)
# method : (Unsecured:0, Secured:1, Extended:3) Ex: 0

provisioning:
uid: 0x41 0xb1 0x85 0x7a 0x0f 0xb6 0xb1 0x48 0xa5 0xe4 0xb9 0xb6 0x03 0x53 0x1b 0x3b
method: 0x00
16 changes: 16 additions & 0 deletions source/unitary_apps/provisioning_joining_node/config_secure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is an example file to customize a node running the provisioning joining node appliation
# using the secure method.

# Hex array must start with 0x otherwise it is treated as a string.

# Format is:
#
# provisioning :
# uid: (bytes string, less than 79 bytes long)
# factory_key : (32 bytes string, [0:15 Auth key][16:31 Enc Key]) Needed for secured method.
# method : (Unsecured:0, Secured:1, Extended:3) Ex: 0

provisioning:
uid: 0x58 0xc8 0x12 0xad 0x37 0xe8 0x36 0x4a 0xa1 0x1f 0x1c 0xbc 0x63 0x3e 0x8e 0x34
factory_key : 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0X09 0X0A 0X0B 0X0C 0X0D 0X0E 0X0F 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0X09 0X0A 0X0B 0X0C 0X0D 0X0E 0X0F
method: 0x01
31 changes: 19 additions & 12 deletions source/unitary_apps/provisioning_joining_node/genConfigHex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_bytes(param):
else:
param = bytes(param, 'utf-8')
elif type(param) is int:
param.to_bytes((param.bit_length() + 7) // 8, byteorder='big')
param = param.to_bytes(max(1, (param.bit_length() + 7) // 8), byteorder='big')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch for the max in case param is 0 !

else:
if type(param) is str:
if param.upper().startswith("0X"):
Expand Down Expand Up @@ -79,7 +79,7 @@ def main():
provisioning."))

parser.add_argument("infilespec",
metavar="INFILESPEC", help="yml personalization file")
metavar="INFILESPEC", default="config.yml", help="yml personalization file")
parser.add_argument("--output", "-o",
metavar="OUTFILESPEC",
help="The output file")
Expand Down Expand Up @@ -116,7 +116,17 @@ def main():
return -1

try:
uid = to_bytes(cfg['provisioning']['uid'])
if "uid" in cfg['provisioning'].keys():
uid = to_bytes(cfg['provisioning']["uid"])
elif cfg['provisioning']["method"] == 3:
node_uid = to_bytes(cfg['provisioning']['node_uid'])
node_uid_type = to_bytes(cfg['provisioning']['node_uid_type'])
authenticator_uid = to_bytes(cfg['provisioning']['authenticator_uid'])
authenticator_uid_type = to_bytes(cfg['provisioning']['authenticator_uid_type'])
uid = authenticator_uid_type + authenticator_uid + node_uid_type + node_uid
else:
raise KeyError

method = to_bytes(cfg['provisioning']['method'])
except KeyError:
sys.stdout.write("%s: UID and Method are mandatory\n" % (pgmname))
Expand All @@ -126,14 +136,14 @@ def main():
except KeyError:
key = b''

sys.stdout.write("%s - UID: %s (len: %d)\n" % (pgmname, uid, len(uid)))
sys.stdout.write("%s - UID: %s (len: %d)\n" % (pgmname, uid.hex(), len(uid)))
sys.stdout.write(
"%s - KEY: %s (len: %d)\n" % (pgmname,
"".join("{:02X}".format(to_int(x)) for x in key), len(key)))
sys.stdout.write("%s - Method: %d\n" % (pgmname, method))
sys.stdout.write("%s - Method: %d\n" % (pgmname, int.from_bytes(method, byteorder='big')))

data = struct.pack("<I", STORAGE_MAGIC) + \
struct.pack("B", method) + \
method + \
struct.pack("B", len(uid)) + \
uid + \
struct.pack("B", len(key)) + \
Expand All @@ -148,12 +158,9 @@ def main():
hextool.save_intel_hex(memory, filename=args.output)
sys.stdout.write("%s - Output file: %s\n" % (pgmname, args.output))
else:
hextool.save_intel_hex(memory,
filename=os.path.splitext(args.infilespec)[0] +
".hex")
sys.stdout.write("%s - Output file: %s\n" %
(pgmname,
os.path.splitext(args.infilespec)[0] + ".hex"))
filename = os.path.splitext(args.infilespec)[0] + ".hex"
hextool.save_intel_hex(memory, filename=filename)
sys.stdout.write("%s - Output file: %s\n" % (pgmname, filename))


# Run main.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define OFFSET_KEY_LEN (m_uid_len + 6)
#define OFFSET_KEY (m_uid_len + 7)

#define MAX_UID_LEN 32
#define MAX_UID_LEN 79
#define MAX_KEY_LEN 32

#define STORAGE_AREA_ID 0x8AE573BA
Expand Down Expand Up @@ -94,14 +94,15 @@ bool Storage_init()
if (!read(STORAGE_AREA_ID, &magic, OFFSET_MAGIC, 4) ||
magic != STORAGE_MAGIC)
{
LOG(LVL_DEBUG, "Error Magic");
return false;
}

/* Read Method. */
if (!read(STORAGE_AREA_ID, &m_method, OFFSET_METHOD, 1) ||
(m_method != PROV_METHOD_UNSECURED && m_method != PROV_METHOD_SECURED))
(m_method != PROV_METHOD_UNSECURED && m_method != PROV_METHOD_SECURED && m_method != PROV_METHOD_EXTENDED_UID))
{

LOG(LVL_DEBUG, "Error Method");
return false;
}

Expand Down