From 80ff8d55ace6b15aab2fec77f8e727614aa99a06 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 7 May 2018 09:01:56 +0200 Subject: [PATCH] bluedroid: use the new socket registering API --- .../bt/bluedroid/btc/profile/std/spp/btc_spp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c b/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c index 82d84b2d0..dcab97865 100644 --- a/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c +++ b/components/bt/bluedroid/btc/profile/std/spp/btc_spp.c @@ -29,7 +29,12 @@ #include #include "esp_vfs.h" #include "esp_vfs_dev.h" +#include "lwip/opt.h" // just for LWIP_SOCKET_OFFSET +/** + * BTC_SPP_FDS is the number of file descriptors this VFS driver registers + */ +#define BTC_SPP_FDS 32 #if (defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE) @@ -828,7 +833,7 @@ static ssize_t spp_vfs_read(int fd, void * dst, size_t size) void btc_spp_vfs_register() { esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_DEFAULT | ESP_VFS_FLAG_SHARED_FD_SPACE, + .flags = ESP_VFS_FLAG_DEFAULT, .write = spp_vfs_write, .open = NULL, .fstat = NULL, @@ -836,8 +841,15 @@ void btc_spp_vfs_register() .read = spp_vfs_read, .fcntl = NULL }; - ESP_ERROR_CHECK(esp_vfs_register_socket_space(&vfs, NULL, &spp_local_param.spp_min_fd, &spp_local_param.spp_max_fd)); + // File descriptors from LWIP_SOCKET_OFFSET to MAX_FDS-1 are registered + // for sockets. So here we register from (LWIP_SOCKET_OFFSET - BTC_SPP_FDS) + // to (LWIP_SOCKET_OFFSET-1) leaving unregistered from 0 to + // .(LWIP_SOCKET_OFFSET - BTC_SPP_FDS - 1). + spp_local_param.spp_min_fd = LWIP_SOCKET_OFFSET - BTC_SPP_FDS; + assert(spp_local_param.spp_min_fd >= 0); //TODO return error instead + spp_local_param.spp_max_fd = LWIP_SOCKET_OFFSET; + ESP_ERROR_CHECK(esp_vfs_register_fd_range(&vfs, NULL, spp_local_param.spp_min_fd, spp_local_param.spp_max_fd));//TODO return error if fails spp_local_param.spp_fd = spp_local_param.spp_min_fd; } -#endif ///defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE \ No newline at end of file +#endif ///defined BTC_SPP_INCLUDED && BTC_SPP_INCLUDED == TRUE