Bluetooth OTS: decoding the directory list object

Hi!

I'm developing an application that uses the bluetooth object transfer service.

I can transfer the directory list object (using OTS_OBJ_ID_DIR_LIST) from the server to the client, but parsing it with bt_ots_client_decode_dirlisting() fails to complete for the final record with return code -22.

Does anyone have a working sample that uses this function? I don't see it used in any samples provided in NCS or zephyr.

This is my shell command function and bt_ots_client_dirlisting_cb callback function.

// *****************************************************************************
static int dirlisting_cb_handler(struct bt_ots_obj_metadata *meta)
{
    LOG_INF("%s", __func__);

    if(!meta)
    {
        return BT_OTS_STOP;
    }

    memcpy(&dirlist[dirlist_obj_count], meta,
           sizeof(dirlist[dirlist_obj_count]));

    bt_ots_metadata_display(meta, 1);

    dirlist_obj_count++;
    return BT_OTS_CONTINUE;
}


// *****************************************************************************
static int bv_ble_ots_shell_decode(const struct shell *sh, size_t argc,
                                   char **argv)
{
    int rc;

    memset(dirlist, 0, sizeof(dirlist));
    dirlist_obj_count = 0;

    rc = bt_ots_client_decode_dirlisting(object.data, object.size.cur,
                                         dirlisting_cb_handler);
    if(rc < 0)
    {
        LOG_ERR("bt_ots_client_decode_dirlisting failed, rc %i", rc);
        return rc;
    }

    return 0;
}

This is the output that I get with 4 test files.

[00:00:47.633,117] <inf> bv_ble_ots_client: dirlisting_cb_handler
[00:00:47.633,148] <inf> bt_otc: --- Displaying 1 metadata records ---
[00:00:47.633,239] <inf> bt_otc: Object ID: 0x0x000000000000
[00:00:47.633,270] <inf> bt_otc: Object name: Directory
[00:00:47.633,270] <inf> bt_otc: Object Current Size: 145
[00:00:47.633,270] <inf> bt_otc: Object Allocate Size: 274797
[00:00:47.633,300] <inf> bt_otc: Properties:0x4
[00:00:47.633,300] <inf> bt_otc:  - read permitted
[00:00:47.633,331] <inf> bv_ble_ots_client: dirlisting_cb_handler
[00:00:47.633,361] <inf> bt_otc: --- Displaying 1 metadata records ---
[00:00:47.633,422] <inf> bt_otc: Object ID: 0x0x000000000100
[00:00:47.633,453] <inf> bt_otc: Object name: test5.txt
[00:00:47.633,483] <inf> bt_otc: Object Current Size: 2128
[00:00:47.633,483] <inf> bt_otc: Object Allocate Size: 274797
[00:00:47.633,483] <inf> bt_otc: Properties:0x4d
[00:00:47.633,514] <inf> bt_otc:  - delete permitted
[00:00:47.633,514] <inf> bt_otc:  - patch permitted
[00:00:47.633,514] <inf> bt_otc:  - read permitted
[00:00:47.633,514] <inf> bt_otc:  - write permitted
[00:00:47.633,544] <inf> bv_ble_ots_client: dirlisting_cb_handler
[00:00:47.633,575] <inf> bt_otc: --- Displaying 1 metadata records ---
[00:00:47.633,666] <inf> bt_otc: Object ID: 0x0x000000000101
[00:00:47.633,697] <inf> bt_otc: Object name: test6.txt
[00:00:47.633,697] <inf> bt_otc: Object Current Size: 1872
[00:00:47.633,697] <inf> bt_otc: Object Allocate Size: 274797
[00:00:47.633,728] <inf> bt_otc: Properties:0x4d
[00:00:47.633,728] <inf> bt_otc:  - delete permitted
[00:00:47.633,728] <inf> bt_otc:  - patch permitted
[00:00:47.633,728] <inf> bt_otc:  - read permitted
[00:00:47.633,758] <inf> bt_otc:  - write permitted
[00:00:47.633,758] <inf> bv_ble_ots_client: dirlisting_cb_handler
[00:00:47.633,789] <inf> bt_otc: --- Displaying 1 metadata records ---
[00:00:47.633,880] <inf> bt_otc: Object ID: 0x0x000000000102
[00:00:47.633,911] <inf> bt_otc: Object name: test7.txt
[00:00:47.633,911] <inf> bt_otc: Object Current Size: 1616
[00:00:47.633,911] <inf> bt_otc: Object Allocate Size: 274797
[00:00:47.633,941] <inf> bt_otc: Properties:0x4d
[00:00:47.633,941] <inf> bt_otc:  - delete permitted
[00:00:47.633,941] <inf> bt_otc:  - patch permitted
[00:00:47.633,972] <inf> bt_otc:  - read permitted
[00:00:47.633,972] <inf> bt_otc:  - write permitted
[00:00:47.633,972] <wrn> bt_otc: incorrect DirListing record length 29, longer than remaining size 27
[00:00:47.633,972] <wrn> bt_otc: DirListing, record 5 invalid
[00:00:47.634,002] <err> bv_ble_ots_client: bt_ots_client_decode_dirlisting failed, rc -22

Any help would be appreciated!

thanks,

Chao

Parents
  • Hi Chao, 
    I haven't used the library myself but from what I can see in the log there must be something wrong with the buffer length and the Dirlisting length byte. 

    Could you try to print out the whole buffer and inspect the 4 test file headers there. 
    We need to check why the last one has length of 29 bytes when the buffer only has 27 left. 

  • Hi Hung,

    Thanks for taking a look at this issue.

    I was able to successfully read the directory object using modified versions of the zephyr provided periperal_ots and central_otc samples.

    However, I wasn't able to get the directory object or client initiated write function working on my application. I get an OACP error 0x06 when issuing a write command from client to server. The main difference between my application and the Zephyr samples is I'm using client and server functionality for both central and peripheral devices.

Reply
  • Hi Hung,

    Thanks for taking a look at this issue.

    I was able to successfully read the directory object using modified versions of the zephyr provided periperal_ots and central_otc samples.

    However, I wasn't able to get the directory object or client initiated write function working on my application. I get an OACP error 0x06 when issuing a write command from client to server. The main difference between my application and the Zephyr samples is I'm using client and server functionality for both central and peripheral devices.

Children
Related