Page 1 of 1

Why does `esp_bt_gap_register_callback` reject NULL callback?

Posted: Sun Aug 23, 2020 9:19 am
by vyo2003
I'm currently digging into Bluetooth stack of ESP32 and have stumped upon one weird thing: esp_bt_gap_register_callback specifically rejects NULL callback, in turn making it impossible to disable callback completely. Here's esp_bt_gap_register_callback:
  1. esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback)
  2. {
  3.     if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  4.         return ESP_ERR_INVALID_STATE;
  5.     }
  6.  
  7.     if (callback == NULL) {
  8.         return ESP_FAIL;
  9.     }
  10.  
  11.     btc_profile_cb_set(BTC_PID_GAP_BT, callback);
  12.     return ESP_OK;
  13. }
The only place callback is retrieved is here:
  1. static inline void btc_gap_bt_cb_to_app(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
  2. {
  3.     esp_bt_gap_cb_t cb = (esp_bt_gap_cb_t)btc_profile_cb_get(BTC_PID_GAP_BT);
  4.     if (cb) {
  5.         cb(event, param);
  6.     }
  7. }
(Note: inline does not do a thing here) As you can see, there's an explicit check for presence of callback. Moreover, callback is NULL by default and it's possible to manually reset it using btc_profile_cb_set directly!

So what's the reason behind banning such reset using simply esp_bt_gap_register_callback?