Skip to content

feature(BluetoothSerial): add pinCode function #2765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

xiongyumail
Copy link

@me-no-dev

Hi,

  • This change enables Bluetooth Serial to use password pairing.

  • libbt.a requires you to recompile the build library to support simple pairing.

  • kconfig: // SSP (Secure Simple Pairing ) disable

#
# Bluetooth
#
CONFIG_BT_ENABLED=y

#
# Bluetooth controller
#
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=
CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY=
CONFIG_BTDM_CONTROLLER_MODE_BTDM=y
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=3
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN=0
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=3
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE_0=y
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE_1=
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4=

#
# MODEM SLEEP Options
#
CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG=y
CONFIG_BTDM_MODEM_SLEEP_MODE_EVED=
CONFIG_BTDM_LPCLK_SEL_MAIN_XTAL=y
CONFIG_BLE_SCAN_DUPLICATE=y
CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y
CONFIG_SCAN_DUPLICATE_BY_ADV_DATA=
CONFIG_SCAN_DUPLICATE_BY_ADV_DATA_AND_DEVICE_ADDR=
CONFIG_SCAN_DUPLICATE_TYPE=0
CONFIG_DUPLICATE_SCAN_CACHE_SIZE=20
CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=
CONFIG_BLUEDROID_ENABLED=y
CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
CONFIG_BLUEDROID_PINNED_TO_CORE_1=
CONFIG_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BTC_TASK_STACK_SIZE=8192
CONFIG_BTU_TASK_STACK_SIZE=4096
CONFIG_BLUEDROID_MEM_DEBUG=
CONFIG_CLASSIC_BT_ENABLED=y
CONFIG_A2DP_ENABLE=y
CONFIG_A2DP_SINK_TASK_STACK_SIZE=2048
CONFIG_A2DP_SOURCE_TASK_STACK_SIZE=2048
CONFIG_BT_SPP_ENABLED=y
CONFIG_HFP_ENABLE=y
CONFIG_HFP_CLIENT_ENABLE=y
CONFIG_HFP_AUDIO_DATA_PATH_PCM=y
CONFIG_HFP_AUDIO_DATA_PATH_HCI=
CONFIG_BT_SSP_ENABLED=
CONFIG_GATTS_ENABLE=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=
CONFIG_GATTS_SEND_SERVICE_CHANGE_AUTO=y
CONFIG_GATTS_SEND_SERVICE_CHANGE_MODE=0
CONFIG_GATTC_ENABLE=y
CONFIG_GATTC_CACHE_NVS_FLASH=
CONFIG_BLE_SMP_ENABLE=y
CONFIG_BT_STACK_NO_LOG=y
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
CONFIG_BLE_HOST_QUEUE_CONGESTION_CHECK=
CONFIG_SMP_ENABLE=y
CONFIG_BT_RESERVE_DRAM=0xdb5c

@chegewara
Copy link
Contributor

espressif/esp-idf#2774

esp_bt_gap_set_pin(pin_type, 4, pin_code);
return true;
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the limit 4 chars?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#define ESP_BT_PIN_CODE_LEN        16                   /*!< Max pin code length */
typedef uint8_t esp_bt_pin_code_t[ESP_BT_PIN_CODE_LEN]; /*!< Pin Code (upto 128 bits) MSB is 0 */

What is the reason for the limitaton?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@me-no-dev
Sorry for the late reply, I will modify the code, rebase and submit again.

@me-no-dev
Copy link
Member

@xiongyumail will you address my question?

@luc-github
Copy link
Contributor

luc-github commented May 21, 2019

Hi @me-no-dev do you plan to add a select menu in ide to choose which bt lib need to be used (with or without pairing)? Or pairing enabled lib will become the new default and only choice ?
I ask here because pair enabled lib is necessary for this PR

@me-no-dev
Copy link
Member

Hi Luc :) I need to check this out. I really do not like to provide two libs and an IDE option, because that option will then need to be propagated to all other boards. And they are quite a few now :D

@luc-github
Copy link
Contributor

Hi, I have no issue to have pair enabled lib as default ^_^. I am just curious and want to anticipated big change.
Thank you for your great work :)

@me-no-dev
Copy link
Member

this option does not exist on the 3.2 branch... i'll leave this here in case it pops out

@IonicEV
Copy link
Contributor

IonicEV commented Sep 16, 2019

latest example_spp_initiator_demo.c shows how to provide default pin codes for 16 and 4 length when challenged in Master mode. I would upload bigger work to allow Pins, SSP and most important Master mode connection in BluetoothSerial[.h|.cpp]. Maybe a better option is to wait a little bit. As this small change would be incorporated in upcoming changes in https://github.com/IonicEV/arduino-esp32/tree/master/libraries/BluetoothSerial/src , although it looks like the progress is very slow with pull requests. There is another issue with when you call this method. You really want to set pin code before you started to accept connections in case of slave, but you can not because of this code would only work after BT stack is initialized with begin(), the default pin_code is not really the answer as you blocking others who are not using any pins.

@luc-github
Copy link
Contributor

@me-no-dev I saw 4.0 idf is released, does it will be integrated in next coming update ? Is this will allow pin integration?
Not pushing, just collecting informations ^_^

@atanisoft
Copy link
Collaborator

@luc-github IDF v4 is only a beta and has breaking changes to v3.x. it will be a while before it is integrated.

@IonicEV
Copy link
Contributor

IonicEV commented Sep 16, 2019

I just pushed the initial code changes (20190916 - initial: support for Master mode, Pin and SSP) to the: https://github.com/IonicEV/arduino-esp32/tree/master/libraries/BluetoothSerial/src
See: examples/SerialToSerialBTM for example app

@luc-github
Copy link
Contributor

@atanisoft thank you. So future update to be able to have bt pairing should be more the 3.3 right ?
@IonicEV your code still need to have to rebuild libbt.a., right ?

@atanisoft
Copy link
Collaborator

So future update to be able to have bt pairing should be more the 3.3 right ?

If that functionality is in IDF v3.3 yes, if not no...

@IonicEV
Copy link
Contributor

IonicEV commented Sep 17, 2019

I took the sources from Heltec-esp8266 which just a copy of this repo it seems. I did not need to recompile/rebuild anything. It is possible you are referring to slave mode pin handling (when it is your ESP32) that request remove master to provide the pin for security. For Master mode - pins worked out of the box without any changes (preset or when challenged for a pin by remote), the discussion about pins are dated Nov 30, 2018 on other forums, so it is being around for quite some time.

@IonicEV
Copy link
Contributor

IonicEV commented Sep 17, 2019

Not sure why Master mode did not receive any attention. ESP32 is way better gear vs. ESP8266 + HC05 "dongle", but by some irony nobody bothered to "show the way" with Master mode, despite the fact all the support was there. I think Master mode would push ESP32 over the top. I saw many folks are struggling with this all over the forums, pretty sure many just gave up on ESP32 BT Master option.

@Skysurfer-14
Copy link

With which ESP-IDF version this solution will work? I've made this changes at my ESP-IDF V3.3 installation and had no success with PIN. There are no compiling errors, but still no PIN on pairing.

@Gcopper22
Copy link

hello is there any option to use static pin for classic bluetooth pairing?I'm using eps32-arduinio core 1.0.5.The disable ssp is working only in 1.0.1 version.Thanks in advance

@Gcopper22
Copy link

Hello, a lot of people also me, we are trying to find an option to set static PIN on Bluetooth classic serial connection when pairing. A way to input custom PIN not the default 123456.An old way was created for 1.0.1 version adding a custom libbt.a file that was disabling ssp as far as i know .We want to be able to have this option on newer versions. I'll appreciate anyone who really want to help

@ingsoc
Copy link

ingsoc commented Apr 16, 2021

Bump

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@muellerryan
Copy link

Bump... Still looking for the option to set a custom pin code. It would save a lot of headaches!

@ingsoc
Copy link

ingsoc commented May 19, 2021 via email

@Gcopper22
Copy link

Any news?,Fixed PIN for Classic BT on 1.0.6 version? Can someone compile libbt.a library with the proper settings to make it finaly worked????

@PilnyTomas
Copy link
Contributor

Closing this PR because it is outdated - suggested functionality was implemented in different PR and is already merged.
One thing is however a red flag for this PR - turning off a feature in sdkconfig which would cause issues for people using the Secure Simple Pairing (SSP)

@PilnyTomas PilnyTomas closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.