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

BLE UART simple authentication after connection made and disconnect if not passed, not pairing

Hi All, I am working on a problem for last 2 days and cannot find a solution, I tried everything and read many posts from others however nothing worked so far, either it seems that this specific problem have not been discussed enough or some samples that may lead to solution were not complete so I cannot put them together to work, so I am hoping someone can help to solve this:

I am using BLE_UART example from DK and simply re-tailor it to my needs, which are simple: - receive commands over BLE UART and do some actions to hardware depending on those commands, such as get data via I2C, etc, switch some pins on remote device, etc, the main functionality I all figured out and it works great.

What I need to do is simple authentication process, where once User is connected, he will have 1 - 2 seconds to send authentication package (essentially just a passkey) that will allow further communication via BLE Uart, if authentication was not provided then disconnect will be commenced and user will be disconnected. I do not want to use pairing or whitelist because my authentication is meant not to protect data or ancrypt connection, etc, it is simply designed just to make sure that if someone accidentally connect to BLE device it wont lock it from others, because obviously once you connect to the bluetooth device, it will no longer be discoverable by other users who may have passkey and want to use it.

So, the way I ave it now is this:

I have a function that updates password from Hardware and keeps it in global variable, "devicePasskey", it is called once upon device power up.

Then I have another function that when user sends passkey in form of text command for example: "passkey=qwerty"  via nus service, will parse it and recognize that this is a passkey command and will extract that passkey and store it in it in variable called "userPasskey" that function

Then I have another function that compares both variables and if they do not match will execute sd_ble_gap_disconnect command and disconnect user.

My dilemma is, once you connect to device how do I properly implement 1 - 2 seconds timeout before I start checking if passkeys match, I tried to use timer examples but unsuccessfully, there seem to be already a timer init command  in main() block,

APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);

so if I understand correctly I can use it and add my event to it, I tried to follow some examples 1:1 and it did not work, perhaps because most examples I saw were about buttons and led lights, I simply need to execute my passwords compare function and if its true then continue and if false then initiate disconnect. 

Any suggestions are welcome, thank you,

Parents
  • Hello,

    Can you please describe what happens when you try to add the timer? Do you get an error somewhere? Does it start advertising? Does the timer start, and do you get a timeout, or none of the above?

    A typical scenario is that the peripheral examples uses the TIMER0 instance. That works well on it's own, but when you blend the SoftDevice into it to enable BLE, the TIMER0 is reserved for the softdevice, and it will cause an error.

    Check your APP_ERROR_CHECK(err_code) calls. If any of them receive an err_code != 0, then the application will restart. I see that you use nRF51. What SDK do you use? SDK12.3.0?

    Try to define DEBUG in your preprocessor defines, and set a breakpoint in the app_error_handler in app_error.c. If the application stops there, then you can get a pointer to which APP_ERROR_HANDLER that received the err_code != 0.

    This being said, what you are trying to implement sounds pretty much like what pairing is already doing. It is ok to do what you describe, and if protecting your data is not important, you should be fine. But if a user does not write the passcode if the peripheral requires it, it will automatically disconnect, and start advertising again. 

    Even if a device is bonded, it is still possible to disable the whitelist during advertising, so that any device can connect to it. This is typically used in Bluetooth devices. The first time you connect to a device, you press a button with the bluetooth logo, and then you will find it. The next time, you can usually connect to it without pressing the button, because they are already paired.

    Best regards,

    Edvin

  • Thank you for helping out, what I ended up doing is actually incrementing counter variable in each time program hits it and measuring how many times CPU hits it in 1 seconds or so, since precise timing is not that important at this moment but rather just have general delay. That worked for now, I am going to revisit using timers attempt in couple days.

Reply
  • Thank you for helping out, what I ended up doing is actually incrementing counter variable in each time program hits it and measuring how many times CPU hits it in 1 seconds or so, since precise timing is not that important at this moment but rather just have general delay. That worked for now, I am going to revisit using timers attempt in couple days.

Children
Related