Skip to content

RDKCOM-5492: RDKBDEV-3336 De-authenticating Hotspot Clients Upon DHCP Failure#818

Open
rhegde114 wants to merge 17 commits intordkcentral:developfrom
rhegde114:develop
Open

RDKCOM-5492: RDKBDEV-3336 De-authenticating Hotspot Clients Upon DHCP Failure#818
rhegde114 wants to merge 17 commits intordkcentral:developfrom
rhegde114:develop

Conversation

@rhegde114
Copy link
Copy Markdown

@rhegde114 rhegde114 commented Jan 6, 2026

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

rhegde114 and others added 5 commits December 4, 2025 13:40
             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
@rhegde114 rhegde114 requested a review from a team as a code owner January 6, 2026 18:49
@pradeeptakdas pradeeptakdas changed the title RDKBDEV-3336:De-authenticating Hotspot Clients Upon DHCP Failure RDKCOM-5492: RDKBDEV-3336 De-authenticating Hotspot Clients Upon DHCP Failure Jan 7, 2026
@pradeeptakdas
Copy link
Copy Markdown
Contributor

Hi @rhegde114
Looks like the branch is out of date, Can you please rebase ?

@rhegde114
Copy link
Copy Markdown
Author

@pradeeptakdas , I have re-synced the branch.

bool marker_list_config_subscribed;
bool wifi_sta_2g_status_subscribed;
bool wifi_sta_5g_status_subscribed;
bool privateHotspotIPSubscribed;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stick to the naming convention

Suggested change
bool privateHotspotIPSubscribed;
bool private_hotspot_ip_subscribed;

}
#endif

static void handlePrivateHotspotClientDisconnect(char *event_name, raw_data_t *p_data, void *userData)
Copy link
Copy Markdown
Contributor

@mateuszCieslak-GL mateuszCieslak-GL Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments before the handler

return;

}
memset(tmp_str, 0, sizeof(tmp_str));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed Review comment

Copy link
Copy Markdown
Contributor

@mateuszCieslak-GL mateuszCieslak-GL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update

}
}
#endif
if(ctrl->privateHotspotIPSubscribed == false) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 64? Why not 18?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed comment

// Copy MAC (characters before '_')
size_t mac_len = tmp - pTmp;
strncpy(mac, pTmp, mac_len);
mac[mac_len] = '\0';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mac[mac_len] = '\0';
mac[sizeof(mac)] = '\0';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed review comment

             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
Copy link
Copy Markdown
Contributor

@mateuszCieslak-GL mateuszCieslak-GL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_t and 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.

Comment on lines +1711 to +1718
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;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
char *tmp = strchr(pTmp, '_');
if (tmp != NULL) {
// Copy MAC (characters before '_')
size_t mac_len = tmp - pTmp;
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
Comment on lines +1728 to +1736
// 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);
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
// Convert index (characters after '_') to integer
index = atoi(tmp + 1);
} else {
wifi_util_error_print(WIFI_CTRL, "%s:%d Invalid format:\n", __func__, __LINE__);
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>).

Suggested change
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);

Copilot uses AI. Check for mistakes.
#endif

/**
* Hotspot app use this to kick stations which won't complete DHCP in time.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar in the new header comment: "Hotspot app use this" should be "Hotspot app uses this".

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
Comment on lines +2119 to +2129
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);
}
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community contribution Contributions from community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants