This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

otThreadSetMasterKey() usage

This function succeeds only when Thread protocols are disabled. my question is: if the Thread protocols are enable,what should I do to disable them  ,now what I do is:

"otThreadSetEnabled(otIns,false);
errornum = otThreadSetMasterKey(otIns,otMasKey);
otThreadSetEnabled(otIns,true);"

but it doesn't work , I need help 

   thanks 

Parents
  • Hi,

    Are you checking the return codes from both otThreadSetEnabled() and otThreadSetMasterKey()?

    Do you get any errors, or is it just not updating the MasterKey?

    Best regards,
    Jørgen

  • How is otMasKey set/defined? I assume this is correct, if you have tested the function before without first enabling Thread, but there is an ASSERT inside the function that checks that the key argument pointer is not NULL.

    Which SDK version and example are you using? Can you reproduce this easily with one of the SDK examples?

  • Yes, the SDK is "nRF5_SDK_for_Thread_and_Zigbee_v4.1.0" , the examples is "examples\multiprotocol\ble_thread\ble_thread_dyn_template"  and the define of otMasKey is:

    otMasterKey *otMasKey;

    otMasKey->m8[0] = 0xff;
    otMasKey->m8[1] = 0xee;
    otMasKey->m8[2] = 0xaa;
    otMasKey->m8[3] = 0xbb;
    otMasKey->m8[4] = 0xcc;
    otMasKey->m8[5] = 0x11;
    otMasKey->m8[6] = 0x00;
    otMasKey->m8[7] = 0x22;
    otMasKey->m8[8] = 0x33;
    otMasKey->m8[9] = 0x44;
    otMasKey->m8[10] = 0x55;
    otMasKey->m8[11] = 0x66;
    otMasKey->m8[12] = 0x77;
    otMasKey->m8[13] = 0x88;
    otMasKey->m8[14] = 0x99;
    otMasKey->m8[15] = 0xdd;

    I think there is no problem with this definition, I have modified this example when ble received some special string, it go into:

    "otThreadSetEnabled(otIns,false);
    errornum = otThreadSetMasterKey(otIns,otMasKey);
    otThreadSetEnabled(otIns,true);"

    then came the question above, what problems can you find about the above ?

     thanks

  • You are creating a pointer to the otMasterKey object, but you do not create the object that it should point to. Assigning values to the pointer itself will not work correctly.

    Try creating an otMasterKey object first, and pass its reference to the otThreadSetMasterKey function:

    otMasterKey otMasKey;
    
    otMasKey.m8[0] = 0xff;
    otMasKey.m8[1] = 0xee;
    otMasKey.m8[2] = 0xaa;
    otMasKey.m8[3] = 0xbb;
    otMasKey.m8[4] = 0xcc;
    otMasKey.m8[5] = 0x11;
    otMasKey.m8[6] = 0x00;
    otMasKey.m8[7] = 0x22;
    otMasKey.m8[8] = 0x33;
    otMasKey.m8[9] = 0x44;
    otMasKey.m8[10] = 0x55;
    otMasKey.m8[11] = 0x66;
    otMasKey.m8[12] = 0x77;
    otMasKey.m8[13] = 0x88;
    otMasKey.m8[14] = 0x99;
    otMasKey.m8[15] = 0xdd;
    
    otThreadSetEnabled(otIns,false);
    errornum = otThreadSetMasterKey(otIns,&otMasKey);
    otThreadSetEnabled(otIns,true);

Reply
  • You are creating a pointer to the otMasterKey object, but you do not create the object that it should point to. Assigning values to the pointer itself will not work correctly.

    Try creating an otMasterKey object first, and pass its reference to the otThreadSetMasterKey function:

    otMasterKey otMasKey;
    
    otMasKey.m8[0] = 0xff;
    otMasKey.m8[1] = 0xee;
    otMasKey.m8[2] = 0xaa;
    otMasKey.m8[3] = 0xbb;
    otMasKey.m8[4] = 0xcc;
    otMasKey.m8[5] = 0x11;
    otMasKey.m8[6] = 0x00;
    otMasKey.m8[7] = 0x22;
    otMasKey.m8[8] = 0x33;
    otMasKey.m8[9] = 0x44;
    otMasKey.m8[10] = 0x55;
    otMasKey.m8[11] = 0x66;
    otMasKey.m8[12] = 0x77;
    otMasKey.m8[13] = 0x88;
    otMasKey.m8[14] = 0x99;
    otMasKey.m8[15] = 0xdd;
    
    otThreadSetEnabled(otIns,false);
    errornum = otThreadSetMasterKey(otIns,&otMasKey);
    otThreadSetEnabled(otIns,true);

Children
Related