-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
Classic BT SPP enhancement (IDFGH-2275) #1923
Classic BT SPP enhancement (IDFGH-2275) #1923
Conversation
* Acceptor can connect on any SCN (SCN=0) esp_spp_start_srv( ESP_SPP_SEC_NONE,ESP_SPP_ROLE_SLAVE, ESP_SPP_ANY_SCN, "SPP_SERVER") ESP_SPP_ANY_SCN is 0 This will enable the server to accept any client connection, regardless of clients SCN * Acceptor can require a SCN (SCN!=0) esp_spp_start_srv( ESP_SPP_SEC_NONE,ESP_SPP_ROLE_SLAVE, 5, "SPP_SERVER"); This will require the client to connect using SCN==5 * SCN is delivered to app on open server connect event. ... case ESP_SPP_SRV_OPEN_EVT: handle = param->srv_open.handle; ESP_LOGI(TAG, "ESP_SPP_SRV_OPEN_EVT handle %d channel %d", handle, param->srv_open.scn); ... This could be used to select differnt "SPP services" by SCN * a few typos found by chance corrected
* Acceptor can connect on any SCN (SCN=0) esp_spp_start_srv( ESP_SPP_SEC_NONE,ESP_SPP_ROLE_SLAVE, ESP_SPP_ANY_SCN, "SPP_SERVER") ESP_SPP_ANY_SCN is 0 This will enable the server to accept any client connection, regardless of clients SCN * Acceptor can require a SCN (SCN!=0) esp_spp_start_srv( ESP_SPP_SEC_NONE,ESP_SPP_ROLE_SLAVE, 5, "SPP_SERVER"); This will require the client to connect using SCN==5 * SCN is delivered to app on open server connect event. ... case ESP_SPP_SRV_OPEN_EVT: handle = param->srv_open.handle; ESP_LOGI(TAG, "ESP_SPP_SRV_OPEN_EVT handle %d channel %d", handle, param->srv_open.scn); ... This could be used to select differnt "SPP services" by SCN * a few typos found by chance corrected
Conflicts: components/bt/bluedroid/api/include/api/esp_spp_api.h components/bt/bluedroid/bta/dm/include/bta_dm_int.h components/bt/bluedroid/bta/include/bta/bta_jv_api.h components/bt/bluedroid/bta/jv/include/bta_jv_int.h components/bt/bluedroid/btc/profile/std/spp/btc_spp.c components/bt/bluedroid/stack/btm/include/btm_int.h components/bt/bluedroid/stack/include/stack/port_api.h
* a missing pointer increment caused error, if available was > 0 after the first iteration of while(available) loop. * changed memory allocation strategy from large fixed size (RFCOMM_DATA_BUF_SIZE) to just the needed size, which will be below MTU
While trying to reduce Heap memory usage, I found a bug that leads to an error, if more than around MTU bytes data is in buffer. The bug affects master, not only this pull request, so the missing pointer operation should be merged to master in all cases. I added a commit to fix these issues. Best, |
Hi @BeckerMarkus , Thanks for sending these fixes and your patience waiting for a response. I've reminded some of the Bluetooth team about this PR and they should review it shortly. Angus |
Hi @BeckerMarkus About your problem, maybe we can solve without any changes.
Can those solve your problem? If those can, I think, enable the server to accept any client connection regardless of clients SCN is not the best solution. |
Hi @blueMoodBHD, discovering the SCN first can be a solution, if both endpoints reside on ESP32 devices, or at least if the initiator side can be configured to work that way. Setting up multiple servers (calling esp_spp_start_srv() multiple times) seems redundant to me, as the first instance can and will handle multiple connections anyway. As mentioned, I'm not sure how helpful the change is to others, the lack of comments up to now make me think not many are interested. Would you please have a look into the changed PORT_WriteDataCO (commit 0bbf700). I think that could help regardless of the other stuff. Best |
Hi @BeckerMarkus , |
* a missing pointer increment caused error, if available was > 0 after the first iteration of while(available) loop. * changed memory allocation strategy from large fixed size (RFCOMM_DATA_BUF_SIZE) to just the needed size, which will be below MTU Cherry-picked from #1923
Hi @projectgus, thanks for merging the bug fix. I feel a bit uncertain about how to proceed from here. While the proposed change works good for me and might help others because it somewhat simplyfies SPP usage (makes the acceptor act more like the user might expect when passing 0 as SCN to esp_spp_start_srv()). On the other side, the rfcomm/spp part has enough of complexity in it from my point of view and it might not be the best idea to add more tricks to it :) - so I completely understand blueMoodBHDs position. So it might be best to close this PR now? Markus |
Hi @BeckerMarkus , I'm probably not the best person to talk to about this, @blueMoodBHD is a member of the Bluetooth team so he understands the details much better than me. To check I do understand correctly:
Is that right?
If it's possible to know the range of SCNs clients will use, I think this seems like a good option. I believe the additional memory usage of each additional SPP slot is pretty small, and this gives you predictable usage if multiple clients connect concurrently. |
HIi @BeckerMarkus , @projectgus , |
Hi @projectgus, @blueMoodBHD, thanks for looking into this again, sorry, I was not clear enough in my last comment. It was more about the right way of dealing with a PR under the given circumstances. As it looks like, the bug fix has been merged, the other part won't be merged and I very well can accept that. But I still think, the changes could be useful, may be to a smaller number of systems i.e. more special cases. So, in that case, should it be me closing the PR or would Angus do that or would it be best to leave it open for a while, just in case someone comes around? Looking at Angus comment makes me think I did not manage to explain the issue in an understandable way, again, sorry for that. Let me retry here, using a few more words just for reference: The situation
The problem
The proposed solution
While that works great for me, the downside is obvious - it introduces more complexity (and maybe bugs, compatibility issues, ...) to an already non trivial construct. I think I made a misjudgement about how useful that change is to others too. Systems that use a SPP acceptor on the ESP32 together with initiators that can not be easily configured to discover the acceptors SCN (like a Bluetooth SPP/RS232 Module, Windows virtual com port,...) can make profit from the change, I thought there should be many of those. In real world, SPP on the ESP32 might not be used that often in such a context because most systems might use BLE now or the initiator side can be easy made to comply with the ESP32 SPP implementation. Markus |
Hi @BeckerMarkus, Regards |
Evaluating Classic BT SPP in acceptor mode, I found issues to connect to the acceptor on the ESP32 using different clients.
While I got a connection from Android and Windows, I could not get a connection using "rfcomm connect" on Ubuntu.
Further, I found it hard to establish concurrent connections.
I placed a question on the esp32.com forum that kept being unanswered, while there are other users that seem to experience similar sounding problems.
After some research I found:
esp_spp_start_srv(
ESP_SPP_SEC_NONE,ESP_SPP_ROLE_SLAVE, 0,"SPP_SERVER")
will make the server choose a free SCN (server channel number), which is 2 on startup but will change for subsequent (concurrent) connections. The connecting client is required to use the servers SCN for the connection to be established.
Android and (my) Windows client, seem to silently try out different SCN's until the connection request is accepted by the ESP32 stack, while on Linux the channel must be known and set as a parameter of "rfcomm connect".
Reading the sources, I found a hint in port_api.c/ RFCOMM_CreateConnection:
...
** Server can call this function with the same scn parameter multiple times if
** it is ready to accept multiple simultaneous connections.
**
** DLCI for the connection is (scn * 2 + 1) if client originates connection or
** existing none initiator multiplexer channel. Otherwise it is (scn * 2).
** For the server DLCI can be changed later if client will be calling it using
** (scn * 2 + 1) dlci.
...
I found no way to configure the stack in a way, that the DLCI update on the server side takes place with the existing code, while its perfectly possible that I missed something fundamental.
The proposed changes work for me:
The introduced changes are heavy and might break nearly everything else, not only RFCOMM/SPP and I'm quite sure that some more work should be done, before merging this pull request.
I'm not sure how important the proposed function is to others, or if I've missed an important point, so please have a look and comment.
Best,
Markus