hostapd: report bssid, ssid and channel over ubus
Imports a function from iw to convert frequencies to channel numbers.
Co-authored-by: David Bauer <mail@david-bauer.net>
Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
[fix potential out of bounds read]
Signed-off-by: David Bauer <mail@david-bauer.net>
(cherry picked from commit 398df62756)
			
			
This commit is contained in:
		 Martin Weinelt
					Martin Weinelt
				
			
				
					committed by
					
						 David Bauer
						David Bauer
					
				
			
			
				
	
			
			
			 David Bauer
						David Bauer
					
				
			
						parent
						
							53c60d4bfa
						
					
				
				
					commit
					3731ffa0ee
				
			| @@ -372,6 +372,32 @@ hostapd_bss_get_features(struct ubus_context *ctx, struct ubus_object *obj, | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* Imported from iw/util.c | ||||||
|  |  *  https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/util.c?id=4b25ae3537af48dbf9d0abf94132e5ba01b32c18#n200 | ||||||
|  |  */ | ||||||
|  | int ieee80211_frequency_to_channel(int freq) | ||||||
|  | { | ||||||
|  | 	/* see 802.11-2007 17.3.8.3.2 and Annex J */ | ||||||
|  | 	if (freq == 2484) | ||||||
|  | 		return 14; | ||||||
|  | 	/* see 802.11ax D6.1 27.3.23.2 and Annex E */ | ||||||
|  | 	else if (freq == 5935) | ||||||
|  | 		return 2; | ||||||
|  | 	else if (freq < 2484) | ||||||
|  | 		return (freq - 2407) / 5; | ||||||
|  | 	else if (freq >= 4910 && freq <= 4980) | ||||||
|  | 		return (freq - 4000) / 5; | ||||||
|  | 	else if (freq < 5950) | ||||||
|  | 		return (freq - 5000) / 5; | ||||||
|  | 	else if (freq <= 45000) /* DMG band lower limit */ | ||||||
|  | 		/* see 802.11ax D6.1 27.3.23.2 */ | ||||||
|  | 		return (freq - 5950) / 5; | ||||||
|  | 	else if (freq >= 58320 && freq <= 70200) | ||||||
|  | 		return (freq - 56160) / 2160; | ||||||
|  | 	else | ||||||
|  | 		return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| static int | static int | ||||||
| hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, | hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, | ||||||
| 		       struct ubus_request_data *req, const char *method, | 		       struct ubus_request_data *req, const char *method, | ||||||
| @@ -380,12 +406,24 @@ hostapd_bss_get_status(struct ubus_context *ctx, struct ubus_object *obj, | |||||||
| 	struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); | 	struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj); | ||||||
| 	void *airtime_table, *dfs_table; | 	void *airtime_table, *dfs_table; | ||||||
| 	struct os_reltime now; | 	struct os_reltime now; | ||||||
|  | 	char ssid[SSID_MAX_LEN + 1]; | ||||||
| 	char phy_name[17]; | 	char phy_name[17]; | ||||||
| 	char mac_buf[20]; | 	char mac_buf[20]; | ||||||
|  | 	size_t ssid_len = SSID_MAX_LEN; | ||||||
|  |  | ||||||
|  | 	if (hapd->conf->ssid.ssid_len < SSID_MAX_LEN) | ||||||
|  | 		ssid_len = hapd->conf->ssid.ssid_len; | ||||||
|  |  | ||||||
| 	blob_buf_init(&b, 0); | 	blob_buf_init(&b, 0); | ||||||
| 	blobmsg_add_string(&b, "status", hostapd_state_text(hapd->iface->state)); | 	blobmsg_add_string(&b, "status", hostapd_state_text(hapd->iface->state)); | ||||||
|  | 	blobmsg_printf(&b, "bssid", MACSTR, MAC2STR(hapd->conf->bssid)); | ||||||
|  |  | ||||||
|  | 	memset(ssid, 0, SSID_MAX_LEN + 1); | ||||||
|  | 	memcpy(ssid, hapd->conf->ssid.ssid, ssid_len); | ||||||
|  | 	blobmsg_add_string(&b, "ssid", ssid); | ||||||
|  |  | ||||||
| 	blobmsg_add_u32(&b, "freq", hapd->iface->freq); | 	blobmsg_add_u32(&b, "freq", hapd->iface->freq); | ||||||
|  | 	blobmsg_add_u32(&b, "channel", ieee80211_frequency_to_channel(hapd->iface->freq)); | ||||||
|  |  | ||||||
| 	snprintf(phy_name, 17, "%s", hapd->iface->phy); | 	snprintf(phy_name, 17, "%s", hapd->iface->phy); | ||||||
| 	blobmsg_add_string(&b, "phy", phy_name); | 	blobmsg_add_string(&b, "phy", phy_name); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user