Quang Anh Trần
Quang Anh Trần

Reputation: 1

Model publication set failed with vendor model on Bluez v5.54

I am currently implementing a Provisioner node based on BlueZ v5.54 with example 'test-mesh' using Python D-Bus API on Raspberry Pi 4. I created a vendor model and try to set configuration for the model.

I tested it through steps, adding appkey to node, binding appkey to model and set publication. 2 first steps are OK except the last one. I tried many times by checking the message format but the Config Model Publication Status message keep shows 'status' field 0x02 - Invalid model.

This is Python code for Config Model Publication Set:

APP_COMPANY_ID = 0x0202

def model_pub_set(model_type):
    friend_crendential_flag = 0
    publish_ttl = 0xFF                              # use default TTL
    step_res = 0x00                                 # step resolution = 100ms
    step_num = 0x00                                 # number of steps = 0 = disable
    # Publish Period = Step Resolution * Number of Steps
    # This means how frequently the model will send a publication message.
    publish_period = (step_num << 6) + step_res
    publish_retransmit_count = 0x000                # no times retransmission
    publish_retransmit_interval_step = 0x00000      # no interval steps
    packet = (dst_addr + 
             (GROUP_ADDRESS << 16) +
             (app_idx << 32) + 
             (friend_crendential_flag << 44) +
             (publish_ttl << 48) + 
             (publish_period << 56) + 
             (publish_retransmit_count << 64) +
             (publish_retransmit_interval_step << 67))
    data = None
    opcode = btmesh_ultis.MODEL_PUBLICATION_SET_OPCODE
    packet_bytes = None
    if model_type == 0:     # Sig Model
        packet += (model << 72)
        packet_bytes = packet.to_bytes(11, byteorder='little')
        data = struct.pack('<B', opcode) + packet_bytes
    elif model_type == 1:     # Vendor Model
        packet_bytes = packet.to_bytes(9, byteorder='little')
        data = struct.pack('<B', opcode) + packet_bytes + struct.pack('<HH', model, APP_COMPANY_ID)
    else:
        print("Invalid input, accept 0 or 1 only")
        return

    node.DevKeySend(app.get_element(element_idx).get_path(), dst_addr, True, net_idx, data,
                    reply_handler=generic_reply_cb,
                    error_handler=generic_error_cb) 

# Callback of Model Subscription 
def model_pub_status(payload):
    res = {}
    res['status'] = int.from_bytes([payload[2]], byteorder='little', signed=False)
    res['ele_address'] = int.from_bytes([payload[3], payload[4]], byteorder='little', signed=False)
    res['pub_address'] = int.from_bytes([payload[5], payload[6]], byteorder='little', signed=False)
    app_credential_flag = int.from_bytes([payload[7], payload[8]], byteorder='little', signed=False)
    res['app_idx'] = app_credential_flag >> 4
    res['credential_flag'] = (app_credential_flag & 0x1000) >> 3
    res['pub_ttl'] = int.from_bytes([payload[9]], byteorder='little', signed=False)
    res['pub_period'] = int.from_bytes([payload[10]], byteorder='little', signed=False)
    publish_retransmit = int.from_bytes([payload[11]], byteorder='little', signed=False)
    res['pub_retrans_count'] = publish_retransmit >> 5
    res['pub_retrans_interval_step'] = (publish_retransmit & 0x11111)
    if (len(payload) == 14):
        res['model'] = int.from_bytes([payload[12], payload[13]], byteorder='little', signed=False)
    else:
        res['model'] = int.from_bytes([payload[12], payload[13], payload[14], payload[15]], byteorder='little', signed=False)
    print(res)

... The rest of code are similar to test-mesh example

Log of console

token  - set node ID (token)
create  - create mesh network
appkey-index  - set AppKey index
appkey-new  - create appkey
scan-start  - scan for near unprovisioned devs
scan-cancel  - cancel scanning
element-index  - set Element index
add  - add device to mesh network
join  - join mesh network
attach  - attach mesh node
remove  - delete node
uuid  - set remote uuid
vendor-send  - send raw vendor message
config-menu  - Node Configuration menu
client-menu  - On/Off client menu
help  - show list command
quit  - exit the test

create
Creating with UUID 0a0102030405060708090a0b0c0d0e0f
Created mesh network with token da1109acea12b0b6
Attach mesh node to bluetooth-meshd daemon
Mesh app registered: /org/bluez/mesh/node0a0102030405060708090a0b0c0d0e0f
appkey-new
Success create app key index 0 in net index 0
config-menu

dest  - set destination address
appkey-add  - add AppKey index in network
appkey-bind  - bind AppKey in model
model  - set model ID
pub-set  - set publication
sub-set  - set subscription
feature  - show node feature
back  - back to main menu
quit  - exit the test

dest
Enter 4-digit hex destination address:
0001
Destination address: 0001

feature
Node 0x0001 properties:
{'feature': {'Relay': 1, 'Proxy': 0, 'Friend': 1, 'Low Energy': 0}, 'elements': [{'IDx:': 0, 'Location': 0, 'SIG Models': [0, 4096, 4097], 'Vendor Models': [33685504]}, {'IDx:': 1, 'Location': 0, 'SIG Models': [4097], 'Vendor Models': []}]}

appkey-add
Success add app key index 0 to node 1
model
Enter model ID 4-digit hex:
0000
Target SIG Model ID: 0000

appkey-bind
Enter 0 to bind SIG model, 1 to bind vendor model:
1
{dbus.String('Vendor'): 514, dbus.String('Bindings'): [0]}
Update Model Config 0000
Bindings: [0]
{'status': 0, 'ele_address': 1, 'app_idx': 0, 'type': 'Vendor', 'model_id': 33685504}

pub-set
Enter 0 to set publication SIG model, 1 to vendor model:
1
{'status': 2, 'ele_address': 1, 'pub_address': 0, 'app_idx': 0, 'credential_flag': 0, 'pub_ttl': 0, 'pub_period': 0, 'pub_retrans_count': 0, 'pub_retrans_interval_step': 0, 'model': 33685504}

Log of bluetooth-meshd related to model publication set:

mesh/node.c:dev_key_send_call() DevKeySend
mesh/model.c:msg_send() (6fff) 0xffb2ab58
mesh/model.c:msg_send() net_idx 0
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/net.c:net_msg_check_replay_cache() Test Replay src: 0001 seq: 000004 iv: 00000000
mesh/util.c:print_packet() 61105.911 Clr Rx: 03010000c00000ff000000000202
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x3 size 13 idx 000
mesh/cfgmod-server.c:config_pub_set() pub_set: status 2, ea 0001, ota: 0000, mod: 202, idx: 000
mesh/model.c:msg_send() (7fff) 0x19f6980
mesh/model.c:msg_send() net_idx 0
mesh/model.c:mesh_model_rx() iv_index 00000000 key_aid = 00
mesh/net.c:net_msg_check_replay_cache() Test Replay src: 0001 seq: 000005 iv: 00000000
mesh/util.c:print_packet() 61105.912 Clr Rx: 80190201000000000000000000000202
mesh/cfgmod-server.c:cfg_srv_pkt() CONFIG-SRV-opcode 0x8019 size 14 idx 000
mesh/model.c:send_dev_key_msg_rcvd() Send "DevKeyMessageReceived"
mesh/net.c:net_msg_add_replay_cache() New Entry for 0001

Upvotes: 0

Views: 26

Answers (0)

Related Questions