summaryrefslogtreecommitdiffstats
path: root/net/wireless
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2019-02-07 17:26:38 -0500
committerJohannes Berg <johannes.berg@intel.com>2019-02-08 07:51:50 -0500
commit49a68e0d88890060a2b9b6c6ad1ec53eb50abccf (patch)
tree5cc73012d8a6e31417bc69bb7be9fc980abc4518 /net/wireless
parentc17e28d1bcd357219264aaab37d5daba8181f9d3 (diff)
cfg80211: add various struct element finding helpers
We currently have a number of helpers to find elements that just return a u8 *, change those to return a struct element and add inlines to deal with the u8 * compatibility. Note that the match behaviour is changed to start the natch at the data, so conversion from _ie_match to _elem_match need to be done carefully. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/wireless')
-rw-r--r--net/wireless/scan.c39
-rw-r--r--net/wireless/util.c6
2 files changed, 20 insertions, 25 deletions
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index c7f64bb9c581..d2c9ca5f4f57 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -480,48 +480,43 @@ void cfg80211_bss_expire(struct cfg80211_registered_device *rdev)
480 __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE); 480 __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE);
481} 481}
482 482
483const u8 *cfg80211_find_ie_match(u8 eid, const u8 *ies, int len, 483const struct element *
484 const u8 *match, int match_len, 484cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len,
485 int match_offset) 485 const u8 *match, unsigned int match_len,
486 unsigned int match_offset)
486{ 487{
487 const struct element *elem; 488 const struct element *elem;
488 489
489 /* match_offset can't be smaller than 2, unless match_len is
490 * zero, in which case match_offset must be zero as well.
491 */
492 if (WARN_ON((match_len && match_offset < 2) ||
493 (!match_len && match_offset)))
494 return NULL;
495
496 for_each_element_id(elem, eid, ies, len) { 490 for_each_element_id(elem, eid, ies, len) {
497 if (elem->datalen >= match_offset - 2 + match_len && 491 if (elem->datalen >= match_offset + match_len &&
498 !memcmp(elem->data + match_offset - 2, match, match_len)) 492 !memcmp(elem->data + match_offset, match, match_len))
499 return (void *)elem; 493 return elem;
500 } 494 }
501 495
502 return NULL; 496 return NULL;
503} 497}
504EXPORT_SYMBOL(cfg80211_find_ie_match); 498EXPORT_SYMBOL(cfg80211_find_elem_match);
505 499
506const u8 *cfg80211_find_vendor_ie(unsigned int oui, int oui_type, 500const struct element *cfg80211_find_vendor_elem(unsigned int oui, int oui_type,
507 const u8 *ies, int len) 501 const u8 *ies,
502 unsigned int len)
508{ 503{
509 const u8 *ie; 504 const struct element *elem;
510 u8 match[] = { oui >> 16, oui >> 8, oui, oui_type }; 505 u8 match[] = { oui >> 16, oui >> 8, oui, oui_type };
511 int match_len = (oui_type < 0) ? 3 : sizeof(match); 506 int match_len = (oui_type < 0) ? 3 : sizeof(match);
512 507
513 if (WARN_ON(oui_type > 0xff)) 508 if (WARN_ON(oui_type > 0xff))
514 return NULL; 509 return NULL;
515 510
516 ie = cfg80211_find_ie_match(WLAN_EID_VENDOR_SPECIFIC, ies, len, 511 elem = cfg80211_find_elem_match(WLAN_EID_VENDOR_SPECIFIC, ies, len,
517 match, match_len, 2); 512 match, match_len, 0);
518 513
519 if (ie && (ie[1] < 4)) 514 if (!elem || elem->datalen < 4)
520 return NULL; 515 return NULL;
521 516
522 return ie; 517 return elem;
523} 518}
524EXPORT_SYMBOL(cfg80211_find_vendor_ie); 519EXPORT_SYMBOL(cfg80211_find_vendor_elem);
525 520
526static bool is_bss(struct cfg80211_bss *a, const u8 *bssid, 521static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
527 const u8 *ssid, size_t ssid_len) 522 const u8 *ssid, size_t ssid_len)
diff --git a/net/wireless/util.c b/net/wireless/util.c
index cd48cdd582c0..61fa33d0019e 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -776,7 +776,7 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb,
776} 776}
777EXPORT_SYMBOL(cfg80211_classify8021d); 777EXPORT_SYMBOL(cfg80211_classify8021d);
778 778
779const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie) 779const struct element *ieee80211_bss_get_elem(struct cfg80211_bss *bss, u8 id)
780{ 780{
781 const struct cfg80211_bss_ies *ies; 781 const struct cfg80211_bss_ies *ies;
782 782
@@ -784,9 +784,9 @@ const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
784 if (!ies) 784 if (!ies)
785 return NULL; 785 return NULL;
786 786
787 return cfg80211_find_ie(ie, ies->data, ies->len); 787 return cfg80211_find_elem(id, ies->data, ies->len);
788} 788}
789EXPORT_SYMBOL(ieee80211_bss_get_ie); 789EXPORT_SYMBOL(ieee80211_bss_get_elem);
790 790
791void cfg80211_upload_connect_keys(struct wireless_dev *wdev) 791void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
792{ 792{