RDKCOM-5492: RDKBDEV-3336 De-authenticating Hotspot Clients Upon DHCP Failure#818
RDKCOM-5492: RDKBDEV-3336 De-authenticating Hotspot Clients Upon DHCP Failure#818rhegde114 wants to merge 17 commits intordkcentral:developfrom
Conversation
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
|
Hi @rhegde114 |
|
@pradeeptakdas , I have re-synced the branch. |
source/core/wifi_ctrl.h
Outdated
| bool marker_list_config_subscribed; | ||
| bool wifi_sta_2g_status_subscribed; | ||
| bool wifi_sta_5g_status_subscribed; | ||
| bool privateHotspotIPSubscribed; |
There was a problem hiding this comment.
stick to the naming convention
| bool privateHotspotIPSubscribed; | |
| bool private_hotspot_ip_subscribed; |
| } | ||
| #endif | ||
|
|
||
| static void handlePrivateHotspotClientDisconnect(char *event_name, raw_data_t *p_data, void *userData) |
There was a problem hiding this comment.
Please add a comment here how does the proper command should look like, and what its supposed to do i.e.
"// Hotspot app will use this to kick stations which won't complete DHCP in time.
// expected command from hotspot app:
// Device.X_COMCAST-COM_GRE.Hotspot.RejectAssociatedClient <mac>_<vap_index>"
There was a problem hiding this comment.
Added comments before the handler
| return; | ||
|
|
||
| } | ||
| memset(tmp_str, 0, sizeof(tmp_str)); |
There was a problem hiding this comment.
since youre already initializing other local variables to zero at the beginning of the function, it would make sense to do the same for tmp_str.
| } | ||
| } | ||
| #endif | ||
| if(ctrl->privateHotspotIPSubscribed == false) { |
There was a problem hiding this comment.
| if(ctrl->privateHotspotIPSubscribed == false) { | |
| if(!ctrl->privateHotspotIPSubscribed) { |
| if(ctrl->privateHotspotIPSubscribed == false) { | ||
| if (bus_desc->bus_event_subs_fn(&ctrl->handle, WIFI_PRIVATE_HOTSPOT_CLIENT_IP,handlePrivateHotspotClientDisconnect, NULL, | ||
| 0) != bus_error_success) { | ||
| wifi_util_info_print(WIFI_CTRL, "%s:%d bus: bus event:%s subscribe fail\n", |
There was a problem hiding this comment.
| wifi_util_info_print(WIFI_CTRL, "%s:%d bus: bus event:%s subscribe fail\n", | |
| wifi_util_error_print(WIFI_CTRL, "%s:%d bus: bus event:%s subscribe fail\n", |
| { | ||
| (void)userData; | ||
| char *pTmp = NULL; | ||
| char mac[64] = {0}; |
| // Copy MAC (characters before '_') | ||
| size_t mac_len = tmp - pTmp; | ||
| strncpy(mac, pTmp, mac_len); | ||
| mac[mac_len] = '\0'; |
There was a problem hiding this comment.
| mac[mac_len] = '\0'; | |
| mac[sizeof(mac)] = '\0'; |
There was a problem hiding this comment.
uchm this one would be dependent on chancing char mac[64] = {0}; to char mac[18], so might be safer to leave it as is - otherwise it will crash some strcpy down the line..
There was a problem hiding this comment.
I am keeping the original changes as mac is declared as char Mac[18], so valid indices are 0 to 17. Writing to Mac[18] is undefined behavior (out of bounds).
There was a problem hiding this comment.
My bad, you are correct. Just add -1, so that it would be sizeof(mac) - 1 and it should be fine.
| pTmp = (char *)p_data->raw_data.bytes; | ||
|
|
||
| if((strcmp(event_name, WIFI_PRIVATE_HOTSPOT_CLIENT_IP) != 0) || (pTmp == NULL)) { | ||
| wifi_util_info_print(WIFI_CTRL,"%s:%d Invalid event received,%s:%x\n", __func__, __LINE__, event_name, p_data->data_type); |
There was a problem hiding this comment.
| wifi_util_info_print(WIFI_CTRL,"%s:%d Invalid event received,%s:%x\n", __func__, __LINE__, event_name, p_data->data_type); | |
| wifi_util_error_print(WIFI_CTRL,"%s:%d Invalid event received,%s:%x\n", __func__, __LINE__, event_name, p_data->data_type); |
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
mateuszCieslak-GL
left a comment
There was a problem hiding this comment.
look ok to me.
due to DHCP failure
Changes: 1. Added Rbus event handler to moniter event from hotspot
component in case of DHCP failure
2. push the event to queue to kick associated client when
event is received
There was a problem hiding this comment.
Pull request overview
Adds an RBUS event subscription in OneWifi to handle hotspot DHCP-failure notifications and trigger de-authentication (kick) of the associated client.
Changes:
- Introduces a new RBUS event handler to parse
<mac>_<vap_index>and enqueue a kick-assoc-devices command. - Subscribes to the new hotspot RBUS event during
bus_subscribe_events(). - Adds a new subscription-state flag to
wifi_ctrl_tand a new event-name macro.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| source/core/wifi_ctrl_rbus_handlers.c | Adds DHCP-failure event handler and subscribes to the new RBUS event. |
| source/core/wifi_ctrl.h | Adds a new *_subscribed flag to track the new event subscription. |
| include/wifi_base.h | Defines the new hotspot RBUS event name constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| wifi_util_dbg_print(WIFI_CTRL, "%s:%d Received event:%s with data type:%x\n", __func__, __LINE__, | ||
| event_name, p_data->data_type); | ||
|
|
||
| pTmp = (char *)p_data->raw_data.bytes; | ||
|
|
||
| if((strcmp(event_name, HOTSPOT_CLIENT_DHCP_FAILURE_DISCONNECTED) != 0) || (pTmp == NULL)) { | ||
| wifi_util_error_print(WIFI_CTRL,"%s:%d Invalid event received,%s:%x\n", __func__, __LINE__, event_name, p_data->data_type); | ||
| return; |
There was a problem hiding this comment.
The event handler dereferences p_data/p_data->raw_data.bytes without validating p_data != NULL and p_data->data_type == bus_data_type_string. Since raw_data.bytes is an untyped pointer with an explicit length (raw_data_len), treating it as a C string can lead to out-of-bounds reads (e.g., strchr, strcmp, strlen) if it is not NUL-terminated. Add p_data/type checks and copy into a bounded local buffer using raw_data_len with explicit NUL termination before parsing/logging.
| char *tmp = strchr(pTmp, '_'); | ||
| if (tmp != NULL) { | ||
| // Copy MAC (characters before '_') | ||
| size_t mac_len = tmp - pTmp; |
There was a problem hiding this comment.
mac_len is derived from the position of '_' and is used to strncpy(mac, pTmp, mac_len) followed by mac[mac_len] = '\0' without checking that mac_len < sizeof(mac). If the payload is malformed (no delimiter early / very long prefix), this will overflow mac and write past the buffer. Validate mac_len against sizeof(mac)-1 (and ideally validate MAC format) before copying.
| size_t mac_len = tmp - pTmp; | |
| size_t mac_len = (size_t)(tmp - pTmp); | |
| if (mac_len == 0 || mac_len >= sizeof(mac)) { | |
| wifi_util_error_print(WIFI_CTRL, "%s:%d Invalid MAC length: %zu\n", | |
| __func__, __LINE__, mac_len); | |
| return; | |
| } |
| // Convert index (characters after '_') to integer | ||
| index = atoi(tmp + 1); | ||
| } else { | ||
| wifi_util_error_print(WIFI_CTRL, "%s:%d Invalid format:\n", __func__, __LINE__); | ||
| return; | ||
|
|
||
| } | ||
| snprintf(tmp_str, sizeof(tmp_str), "%d-%s-20", (index-1),mac); | ||
| push_event_to_ctrl_queue(tmp_str, (strlen(tmp_str) + 1), wifi_event_type_command, wifi_event_type_command_kick_assoc_devices, NULL); |
There was a problem hiding this comment.
atoi(tmp + 1) provides no error reporting and will silently return 0 for non-numeric input. Since you later use (index - 1) to build the kick command, invalid/0 input becomes -1 and will propagate into process_kick_assoc_devices_event (where it becomes an out-of-range UINT vap index). Use strtol with end-pointer validation and enforce an expected range (e.g., index > 0 and wifi_util_is_vap_index_valid(..., index-1)), returning early on invalid values.
| // Convert index (characters after '_') to integer | ||
| index = atoi(tmp + 1); | ||
| } else { | ||
| wifi_util_error_print(WIFI_CTRL, "%s:%d Invalid format:\n", __func__, __LINE__); |
There was a problem hiding this comment.
The error log "Invalid format:\n" is missing the offending payload and has an extra space, which makes diagnosing bad hotspot messages harder. Include the received data (bounded by raw_data_len) and clarify the expected format (<mac>_<vap_index>).
| wifi_util_error_print(WIFI_CTRL, "%s:%d Invalid format:\n", __func__, __LINE__); | |
| wifi_util_error_print(WIFI_CTRL, | |
| "%s:%d Invalid format for hotspot payload; expected '<mac>_<vap_index>', got '%.*s'\n", | |
| __func__, __LINE__, (int)p_data->raw_data_len, (char *)p_data->raw_data.bytes); |
| #endif | ||
|
|
||
| /** | ||
| * Hotspot app use this to kick stations which won't complete DHCP in time. |
There was a problem hiding this comment.
Grammar in the new header comment: "Hotspot app use this" should be "Hotspot app uses this".
| * Hotspot app use this to kick stations which won't complete DHCP in time. | |
| * Hotspot app uses this to kick stations which won't complete DHCP in time. |
| if(!ctrl->hotspot_client_dhcp_failure_subscribed) { | ||
| if (bus_desc->bus_event_subs_fn(&ctrl->handle, HOTSPOT_CLIENT_DHCP_FAILURE_DISCONNECTED, hotspot_client_dhcp_failure_disconnect, NULL, | ||
| 0) != bus_error_success) { | ||
| wifi_util_error_print(WIFI_CTRL, "%s:%d bus: bus event:%s subscribe fail\n", | ||
| __FUNCTION__, __LINE__, HOTSPOT_CLIENT_DHCP_FAILURE_DISCONNECTED); | ||
| } else { | ||
| ctrl->hotspot_client_dhcp_failure_subscribed = true; | ||
| wifi_util_info_print(WIFI_CTRL, "%s:%d bus: bus event:%s subscribe success\n", | ||
| __FUNCTION__, __LINE__, HOTSPOT_CLIENT_DHCP_FAILURE_DISCONNECTED); | ||
| } | ||
| } |
There was a problem hiding this comment.
If this subscription fails at boot, it may never be retried: bus_check_and_subscribe_events() (source/core/wifi_ctrl.c) only checks other *_subscribed flags and does not include hotspot_client_dhcp_failure_subscribed. Consider adding this flag to that retry condition (and initializing/resetting it consistently with the other subscribe flags) so transient bus failures don’t permanently disable DHCP-failure deauth.
Develop an event subscription handler in OneWifi to process the event received from hotspot component upon DHCP failure and initiated de-authentication of associated client
Dependent on rdkcentral/hotspot#32