-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Bluetooth: rfcomm: Support dynamic channel allocation #83785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,15 +199,32 @@ rfcomm_sessions_lookup_bt_conn(struct bt_conn *conn) | |
|
||
int bt_rfcomm_server_register(struct bt_rfcomm_server *server) | ||
{ | ||
if (server->channel < RFCOMM_CHANNEL_START || | ||
server->channel > RFCOMM_CHANNEL_END || !server->accept) { | ||
if (server->channel > RFCOMM_CHANNEL_END || !server->accept) { | ||
return -EINVAL; | ||
} | ||
|
||
/* Check if given channel is already in use */ | ||
if (rfcomm_server_lookup_channel(server->channel)) { | ||
LOG_DBG("Channel already registered"); | ||
return -EADDRINUSE; | ||
if (!server->channel) { | ||
uint8_t chan = (uint8_t)BT_RFCOMM_CHAN_DYNAMIC_START; | ||
|
||
for (; chan <= RFCOMM_CHANNEL_END; chan++) { | ||
/* Check if given channel is already in use */ | ||
if (!rfcomm_server_lookup_channel(chan)) { | ||
server->channel = chan; | ||
LOG_DBG("Allocated channel 0x%02x for new server", chan); | ||
break; | ||
} | ||
} | ||
Comment on lines
+209
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to add one lock to avoid that the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the style of the Bleutooth stack. For example, the l2cap psm allocation of BLE does not have such protection. And So I think the case your description is not including in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Maybe it can be improved later. |
||
|
||
if (!server->channel) { | ||
LOG_WRN("No free dynamic rfcomm channels available"); | ||
return -EADDRNOTAVAIL; | ||
} | ||
} else { | ||
/* Check if given channel is already in use */ | ||
if (rfcomm_server_lookup_channel(server->channel)) { | ||
LOG_WRN("Channel already registered"); | ||
return -EADDRINUSE; | ||
} | ||
} | ||
|
||
LOG_DBG("Channel 0x%02x", server->channel); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`RFCOMM_CHANNEL_START' definition can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used to
support the dynamic channel allocation if the passed channel is zero.