Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Bluetooth Low Energy (BLE) Security via Encryption

    Scheduled Pinned Locked Moved WiPy 2&3
    bluetoothencryption
    7 Posts 4 Posters 2.4k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      semireg
      last edited by semireg

      Are there any plans to expand the Bluetooth Low Energy APIs to include pairing with authentication and encryption? Most of my experience is using BLE as-is. Can the ESP32 support more secure BLE data transfers?

      References

      • https://github.com/espressif/esp-idf/blob/17e8d49/examples/bluetooth/gatt_security_client/tutorial/Gatt_Security_Client_Example_Walkthrough.md
      • https://eewiki.net/display/Wireless/A+Basic+Introduction+to+BLE+Security
      • https://duo.com/decipher/understanding-bluetooth-security
      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @semireg
        last edited by jmarcelino

        @semireg
        The ESP32 and ESP-IDF support this it just hasnt’t been brought into Python yet. It is planned to be but I can’t offer an ETA.

        N 1 Reply Last reply Reply Quote 1
        • S Offline
          semireg
          last edited by semireg

          @jmarcelino, I'm beginning to work on this. Quick question about the C toolchain...

          The function esp_ble_gap_set_security_param is within esp_gap_ble_api.h but is gated by #if (SMP_INCLUDED == TRUE).

          The only reference I see is in esp32/build/WIPY/release/genhdr/qstr.i.last which is obviously generated and looks like:

          #define BTC_PRF_QUEUE_INCLUDED FALSE
          #define BTC_GAP_BT_INCLUDED FALSE
          #define BTC_AV_INCLUDED FALSE
          
          
          
          
          #define GATTS_INCLUDED TRUE
          
          
          
          
          
          #define GATTC_INCLUDED TRUE
          # 108 "/home/user/pycom/pycom-esp-idf/components/bt/bluedroid/include/bt_target.h"
          #define SMP_INCLUDED FALSE
          #define BLE_PRIVACY_SPT FALSE
          
          
          
          #define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS
          #define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS
          

          I also noticed that sdkconfig.h contains references to options such as #define CONFIG_GATTC_ENABLE 1 but also reads Automatically generated file; DO NOT EDIT..

          Can you offer any pointers on how to familiarize myself with the toolchain to enable the use of esp_ble_gap_set_security_param?

          Update 1
          The dir pycom-esp-idf (ESP-IDF SDK) file components/bt/bluedroid/include/bt_target.h contains:

          #if (CONFIG_SMP_ENABLE)
          #define SMP_INCLUDED              TRUE
          #define BLE_PRIVACY_SPT           TRUE
          #else
          #define SMP_INCLUDED              FALSE
          #define BLE_PRIVACY_SPT           FALSE
          #endif  /* CONFIG_GATTC_ENABLE */
          

          Interestingly, this thread describes the relationships as:

          The sdkconfig.h file is generated from the ESP32 environment. Assuming platformio wasn’t present, one would download the ESP-IDF SDK and then download an application template (both from Github). One would then run the make command to build a tool …
          make menuconfig
          When run, this produces a terminal based application which shows menus for the configuration of an ESP32 environment. This contains a wealth of options and it is extremely common to modify these options on a project by project basis. For example, one can describe that one wants Bluetooth or WiFi or change the baud rate for upload or change the diagnostics logging levels. Once the tool has been run, a file called “sdkconfig” is generated which contains your saved settings. In addition, a file called “sdkconfig,h” is built which is the missing file needed for ESP32 ESP-IDF application compilation.

          That said, it seems that for now it's safe to edit sdkconfig.h and add #define CONFIG_SMP_ENABLE=1. Running make clean; make regenerated build/WIPY/release/genhdr/qstr.i.last and tried to build the source but references to esp_ble_gap_set_security_param still create an undefined reference error when linking. Frustrating...

          Update 2
          The lib/libbt.a that ships with pycom-micropython-sigfox isn't rebuilt from the ESP-IDF SDK. The symbols can be verified using nm lib/libbt.a | grep esp_ble_gap_set_security_param. If this symbol is missing then the result will be "undefined reference" when linking (above).

          One way to work-around this is to cd to pycom-esp-idf/examples/bluetooth/gatt_security_server/ and run make. The resulting build/bt/libbt.a can be copied to pycom-micropython-sigfox/esp32/lib/ and with that the build should succeed. The next step is to figure out how to setup the PyCom toolchain so that this process can be repeated within a "normal" build.

          1 Reply Last reply Reply Quote 0
          • S Offline
            semireg
            last edited by

            While implementing "pairing failure reasons" I came across a minor documentation issue upstream: https://github.com/espressif/esp-idf/issues/1845

            1 Reply Last reply Reply Quote 0
            • S Offline
              semireg
              last edited by

              My work so far looks promising. I'm able to assign characteristic properties that include encryption and iOS/MacOS/Android devices show the pairing prompt when the characteristic is accessed. The issue that I'm currently facing is a very short timeout that makes it impossible to enter the key. I've logged an issue with the ESP-IDF project to see if they have any ideas.

              1 Reply Last reply Reply Quote 0
              • DerickD Offline
                Derick Banned
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • N Offline
                  nestorld @jmarcelino
                  last edited by

                  Hello @jmarcelino, do you know if this is already available in any Pycom's firmware?

                  Néstor López

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom