roboswitch: Minor coding style cleanup

This commit is contained in:
Jouni Malinen 2008-11-18 16:35:08 +02:00
parent e519314ee9
commit 9ef21b2fef

View file

@ -114,11 +114,10 @@ static int wpa_driver_roboswitch_reg(struct wpa_driver_roboswitch_data *drv,
/* check if operation completed */ /* check if operation completed */
for (i = 0; i < ROBO_MII_RETRY_MAX; ++i) { for (i = 0; i < ROBO_MII_RETRY_MAX; ++i) {
if ((wpa_driver_roboswitch_mdio_read(drv, ROBO_MII_ADDR) & 3) == if ((wpa_driver_roboswitch_mdio_read(drv, ROBO_MII_ADDR) & 3)
0) { == 0)
return 0; return 0;
} }
}
/* timeout */ /* timeout */
return -1; return -1;
} }
@ -130,13 +129,14 @@ static int wpa_driver_roboswitch_read(struct wpa_driver_roboswitch_data *drv,
int i; int i;
if (len > ROBO_MII_DATA_MAX || if (len > ROBO_MII_DATA_MAX ||
wpa_driver_roboswitch_reg(drv, page, reg, ROBO_MII_ADDR_READ) < 0) { wpa_driver_roboswitch_reg(drv, page, reg, ROBO_MII_ADDR_READ) < 0)
return -1; return -1;
}
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
val[i] = wpa_driver_roboswitch_mdio_read(drv, val[i] = wpa_driver_roboswitch_mdio_read(
ROBO_MII_DATA_OFFSET + i); drv, ROBO_MII_DATA_OFFSET + i);
} }
return 0; return 0;
} }
@ -186,27 +186,28 @@ static int wpa_driver_roboswitch_join(struct wpa_driver_roboswitch_data *drv,
u16 addr_word[ETH_ALEN / 2]; u16 addr_word[ETH_ALEN / 2];
/* RoboSwitch uses 16-bit Big Endian addresses. */ /* RoboSwitch uses 16-bit Big Endian addresses. */
/* The ordering of the words is reversed in the MII registers. */ /* The ordering of the words is reversed in the MII registers. */
for (i = 0; i < ETH_ALEN; i += 2) { for (i = 0; i < ETH_ALEN; i += 2)
addr_word[(ETH_ALEN - i) / 2 - 1] = WPA_GET_BE16(addr + i); addr_word[(ETH_ALEN - i) / 2 - 1] = WPA_GET_BE16(addr + i);
}
/* check if multiport addresses are not yet enabled */ /* check if multiport addresses are not yet enabled */
if (wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, if (wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_CONF, &_read, 1) < 0) { ROBO_ARLCTRL_CONF, &_read, 1) < 0)
return -1; return -1;
}
if (!(_read & (1 << 4))) { if (!(_read & (1 << 4))) {
_read |= 1 << 4; _read |= 1 << 4;
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_ADDR_1, addr_word, 3); ROBO_ARLCTRL_ADDR_1, addr_word, 3);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_1, &drv->ports, 1); ROBO_ARLCTRL_VEC_1, &drv->ports,
1);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_2, &zero, 1); ROBO_ARLCTRL_VEC_2, &zero, 1);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_CONF, &_read, 1); ROBO_ARLCTRL_CONF, &_read, 1);
return 0; return 0;
} }
/* check if multiport address 1 is free */ /* check if multiport address 1 is free */
wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, ROBO_ARLCTRL_VEC_1, wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, ROBO_ARLCTRL_VEC_1,
&_read, 1); &_read, 1);
@ -214,7 +215,8 @@ static int wpa_driver_roboswitch_join(struct wpa_driver_roboswitch_data *drv,
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_ADDR_1, addr_word, 3); ROBO_ARLCTRL_ADDR_1, addr_word, 3);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_1, &drv->ports, 1); ROBO_ARLCTRL_VEC_1, &drv->ports,
1);
return 0; return 0;
} }
/* check if multiport address 2 is free */ /* check if multiport address 2 is free */
@ -224,9 +226,11 @@ static int wpa_driver_roboswitch_join(struct wpa_driver_roboswitch_data *drv,
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_ADDR_2, addr_word, 3); ROBO_ARLCTRL_ADDR_2, addr_word, 3);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_2, &drv->ports, 1); ROBO_ARLCTRL_VEC_2, &drv->ports,
1);
return 0; return 0;
} }
/* out of free multiport addresses */ /* out of free multiport addresses */
return -1; return -1;
} }
@ -241,9 +245,9 @@ static int wpa_driver_roboswitch_leave(struct wpa_driver_roboswitch_data *drv,
u16 _read[3], zero = 0; u16 _read[3], zero = 0;
/* same as at join */ /* same as at join */
u16 addr_word[ETH_ALEN / 2]; u16 addr_word[ETH_ALEN / 2];
for (i = 0; i < ETH_ALEN; i += 2) {
for (i = 0; i < ETH_ALEN; i += 2)
addr_word[(ETH_ALEN - i) / 2 - 1] = WPA_GET_BE16(addr + i); addr_word[(ETH_ALEN - i) / 2 - 1] = WPA_GET_BE16(addr + i);
}
/* find our address/vector pair */ /* find our address/vector pair */
for (i = 0; i < 4; i += 2) { for (i = 0; i < 4; i += 2) {
@ -257,8 +261,10 @@ static int wpa_driver_roboswitch_leave(struct wpa_driver_roboswitch_data *drv,
} }
} }
/* check if we found our address/vector pair and deactivate it */ /* check if we found our address/vector pair and deactivate it */
if (i == 4) return -1; if (i == 4)
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, mport[i], &zero, 1); return -1;
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, mport[i], &zero,
1);
/* leave the multiport registers in a sane state */ /* leave the multiport registers in a sane state */
wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, ROBO_ARLCTRL_VEC_1, wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, ROBO_ARLCTRL_VEC_1,
@ -268,10 +274,12 @@ static int wpa_driver_roboswitch_leave(struct wpa_driver_roboswitch_data *drv,
ROBO_ARLCTRL_VEC_2, _read, 1); ROBO_ARLCTRL_VEC_2, _read, 1);
if (_read[0] == 0) { if (_read[0] == 0) {
wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_CONF, _read, 1); ROBO_ARLCTRL_CONF, _read,
1);
_read[0] &= ~(1 << 4); _read[0] &= ~(1 << 4);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_CONF, _read, 1); ROBO_ARLCTRL_CONF, _read,
1);
} else { } else {
wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_ADDR_2, _read, ROBO_ARLCTRL_ADDR_2, _read,
@ -280,7 +288,8 @@ static int wpa_driver_roboswitch_leave(struct wpa_driver_roboswitch_data *drv,
ROBO_ARLCTRL_ADDR_1, _read, ROBO_ARLCTRL_ADDR_1, _read,
3); 3);
wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_read(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_2, _read, 1); ROBO_ARLCTRL_VEC_2, _read,
1);
wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE, wpa_driver_roboswitch_write(drv, ROBO_ARLCTRL_PAGE,
ROBO_ARLCTRL_VEC_1, _read, ROBO_ARLCTRL_VEC_1, _read,
1); 1);
@ -303,7 +312,10 @@ static void * wpa_driver_roboswitch_init(void *ctx, const char *ifname)
if (drv == NULL) return NULL; if (drv == NULL) return NULL;
drv->ctx = ctx; drv->ctx = ctx;
while (ifname[++len]) if (ifname[len] == '.') sep = len; while (ifname[++len]) {
if (ifname[len] == '.')
sep = len;
}
if (sep < 0 || sep >= len - 1) { if (sep < 0 || sep >= len - 1) {
wpa_printf(MSG_INFO, "%s: No <interface>.<vlan> pair in " wpa_printf(MSG_INFO, "%s: No <interface>.<vlan> pair in "
"interface name %s", __func__, ifname); "interface name %s", __func__, ifname);