using SMP service with file system (lfs)

hello Nordic

i am using nrf52832 and nrf52840, working with ncs v2.3.0

currently i am using the SMP service for DFU but i also want to use the service's property to work directly with file system.

1. i saw a mention about security but if i have a secure connection (by second stage pairing), i am guessing the risk is not there right ?

2. in the following link and other places i looked i saw only read and wright commands, no delete option so my question is, what if i want to update/rewrite a file or, delete a file from file system, with the SMP service/ mcumgr, how can it be achieved ?

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/device_mgmt/smp_groups/smp_group_8.html

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/mgmt/mcumgr/smp_svr/README.html

3. is there a minimal block/frame size to read/write to lfs, no only in limitation but in what size of frames is the data written to lfs and is it configurable ? 

 hope to read from you soon

best regards

Ziv

Parents
  • Hi Ziv, 

    1.There is no security feature implemented in SMP. You would  need to implement your own code on top of the SMP service for that. However as you already pointed out you can use general Bluetooth pairing to prevent unauthorized access. As long as you can perform the pairing in a secured way (level 3 or 4) the link is encrypted (AES 128) and the access is authorized. 

    2. You would need to use file upload to overwrite the existing file. https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/device_mgmt/smp_groups/smp_group_8.html#file-upload

    3. I'm not so sure. You may need to do your own search. But as far as I know it should be the multiple of 64. 

  • hi Hung 

    You would need to use file upload to overwrite the existing

    ok, just to better understand, in file system, isn't it deleting an area in flash before writing on it ? is it happening under the hood ? and do i have some why to only delete a file using the mcumgr/SMP service API ?

    3. I'm not so sure. You may need to do your own search. But as far as I know it should be the multiple of 64. 

    i actually did not find so this is why i asked. what stands behind this question is to know how to better manage, divide or connect data to a file to be efficient, i would consider to have structs of data close to the size of a file frame in the lfs. for that i need to understand what is the minimal size block for a file 

    hope to read from you soon

    best regards

    Ziv 

  • Hi Ziv, 
    I dont have much experience with the SMP protocol, but have you looked at the specification ? 

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/device_mgmt/smp_groups/smp_group_8.html#mcumgr-smp-group-8

    When you upload a chunk you will receive a file upload response that tell at which offset it has received the file chunk. 

  • hi Hung

    it seems there is no event for upload done on the receiving side with the ncs

    (i wonder how to suggest to add one to zephyr)

    When you upload a chunk you will receive a file upload response that tell at which offset it has received the file chunk

    not sure i understand, this part of code is in the ncs and i don't think its a good practice to add my code there.

    maybe you know if there is an option to register for an event of fs_close() for specific file in lfs ?

    if not, maybe i can create an event and publish it with zbus ?

    what do you think ?

    hope to read from you soon

    best regards

    Ziv

  • Hi Ziv,
    You can take a look at this guidelines to send a request or contribution to Zephyr: https://docs.zephyrproject.org/latest/contribute/index.html#general-guidelines

    There is a Zephyr's Discord channel that you can post your question : https://discord.com/invite/Ck7jw53nU2

    As I mentioned I haven't worked with the SMP protocol, but I believe that what I pointed you to doesn't require you to modify the SMP protocol. What I pointed you to is part of the SMP protocol:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/device_mgmt/smp_protocol.html 
    For example file status request is Opcode 0, Group ID 8, Command ID 1

    If you write your own Bluetooth SMP client you should be able to send such command and wait for the file status response back. 


  • hi Hung

    You can take a look at this guidelines to send a request or contribution to

    i'll look to it

    There is a Zephyr's Discord channel that you can post your question

    i know, this is actually how i know there is no such event of upload done in smp 

    this is why i asked :

    maybe you know if there is an option to register for an event of fs_close() for specific file in lfs ?

    without any regards to SMP

    For example file status request is Opcode 0, Group ID 8, Command ID 1

    i am familiare with that but i am looking for the server how receives the file to know when it has finished and not to poll from the client to know when it is done and send another commend for the server to read the file

    if you know about the lfs that would be nice, if not then i will close this thread once i have a PR ready in zephyr with the addition of the event

    best regards

    Ziv

  • Hi Ziv, 


    Sorry that I couldn't do much help here. But doesn't the client send a close file command after it's done uploading the file ?

    The server should receive a File Close request from the client. Maybe you can inspect how the phone does a DFU update via BLE to check if the phone send such File Close request or not. 

Reply
  • Hi Ziv, 


    Sorry that I couldn't do much help here. But doesn't the client send a close file command after it's done uploading the file ?

    The server should receive a File Close request from the client. Maybe you can inspect how the phone does a DFU update via BLE to check if the phone send such File Close request or not. 

Children
  •  did you figure this out? I want to use reuse the SMP from MCUBoot and was thinking how I would approach this. I am using littlefs as well.

  • hi Icj

    we have added a separate follow up command from the central after it finishes the upload it will send apply command for the peripheral to read the file that was uploaded