Commit 092f239e authored by Sergio Paracuellos's avatar Sergio Paracuellos Committed by Greg Kroah-Hartman

staging: ks7010: refactor ks_wlan_set_pmksa function

This commit cleans a bit ks_wlan_set_pmksa function removing
nonsense comments as well as make use of ether_addr_* family
functions written to not do manually things that were being
here. Minor single if brackets has been removed also.
Signed-off-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bf338a90
...@@ -1694,68 +1694,65 @@ static int ks_wlan_set_pmksa(struct net_device *dev, ...@@ -1694,68 +1694,65 @@ static int ks_wlan_set_pmksa(struct net_device *dev,
switch (pmksa->cmd) { switch (pmksa->cmd) {
case IW_PMKSA_ADD: case IW_PMKSA_ADD:
if (list_empty(&priv->pmklist.head)) { /* new list */ if (list_empty(&priv->pmklist.head)) {
for (i = 0; i < PMK_LIST_MAX; i++) { for (i = 0; i < PMK_LIST_MAX; i++) {
pmk = &priv->pmklist.pmk[i]; pmk = &priv->pmklist.pmk[i];
if (memcmp("\x00\x00\x00\x00\x00\x00", if (is_zero_ether_addr(pmk->bssid))
pmk->bssid, ETH_ALEN) == 0) break;
break; /* loop */
} }
memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
list_add(&pmk->list, &priv->pmklist.head); list_add(&pmk->list, &priv->pmklist.head);
priv->pmklist.size++; priv->pmklist.size++;
break; /* case */ break;
} }
/* search cache data */ /* search cache data */
list_for_each(ptr, &priv->pmklist.head) { list_for_each(ptr, &priv->pmklist.head) {
pmk = list_entry(ptr, struct pmk, list); pmk = list_entry(ptr, struct pmk, list);
if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) { if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) {
memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
list_move(&pmk->list, &priv->pmklist.head); list_move(&pmk->list, &priv->pmklist.head);
break; /* list_for_each */ break;
} }
} }
if (ptr != &priv->pmklist.head) /* not find address. */ /* not find address. */
break; /* case */ if (ptr != &priv->pmklist.head)
break;
if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */ /* new cache data */
if (priv->pmklist.size < PMK_LIST_MAX) {
for (i = 0; i < PMK_LIST_MAX; i++) { for (i = 0; i < PMK_LIST_MAX; i++) {
pmk = &priv->pmklist.pmk[i]; pmk = &priv->pmklist.pmk[i];
if (memcmp("\x00\x00\x00\x00\x00\x00", if (is_zero_ether_addr(pmk->bssid))
pmk->bssid, ETH_ALEN) == 0) break;
break; /* loop */
} }
memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
list_add(&pmk->list, &priv->pmklist.head); list_add(&pmk->list, &priv->pmklist.head);
priv->pmklist.size++; priv->pmklist.size++;
} else { /* overwrite old cache data */ } else { /* overwrite old cache data */
pmk = list_entry(priv->pmklist.head.prev, struct pmk, pmk = list_entry(priv->pmklist.head.prev, struct pmk,
list); list);
memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data);
memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
list_move(&pmk->list, &priv->pmklist.head); list_move(&pmk->list, &priv->pmklist.head);
} }
break; break;
case IW_PMKSA_REMOVE: case IW_PMKSA_REMOVE:
if (list_empty(&priv->pmklist.head)) { /* list empty */ if (list_empty(&priv->pmklist.head))
return -EINVAL; return -EINVAL;
}
/* search cache data */ /* search cache data */
list_for_each(ptr, &priv->pmklist.head) { list_for_each(ptr, &priv->pmklist.head) {
pmk = list_entry(ptr, struct pmk, list); pmk = list_entry(ptr, struct pmk, list);
if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) { if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) {
eth_zero_addr(pmk->bssid); eth_zero_addr(pmk->bssid);
memset(pmk->pmkid, 0, IW_PMKID_LEN); memset(pmk->pmkid, 0, IW_PMKID_LEN);
list_del_init(&pmk->list); list_del_init(&pmk->list);
break; break;
} }
} }
if (ptr == &priv->pmklist.head) { /* not find address. */ /* not find address. */
if (ptr == &priv->pmklist.head)
return 0; return 0;
}
break; break;
case IW_PMKSA_FLUSH: case IW_PMKSA_FLUSH:
memset(&priv->pmklist, 0, sizeof(priv->pmklist)); memset(&priv->pmklist, 0, sizeof(priv->pmklist));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment