Skip to content

Commit

Permalink
combat for rtwn driver. sync net80211.
Browse files Browse the repository at this point in the history
  • Loading branch information
zxystd committed Dec 3, 2020
1 parent df94da8 commit c2f2c51
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 60 deletions.
7 changes: 7 additions & 0 deletions itl80211/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ MSEC_TO_NSEC(uint64_t milliseconds)
return milliseconds * 1000000ULL;
}

#define MHLEN mbuf_get_mhlen()
#define M_DONTWAIT MBUF_DONTWAIT
#define M_EXT MBUF_EXT
#define m_freem mbuf_freem
#define m_free mbuf_free
#define m_copydata mbuf_copydata

static inline int
flsl(long mask)
{
Expand Down
8 changes: 8 additions & 0 deletions itl80211/openbsd/net80211/ieee80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ ieee80211_ifattach(struct _ifnet *ifp)
memcpy(((struct arpcom *)ifp)->ac_enaddr, ic->ic_myaddr,
ETHER_ADDR_LEN);
// ether_ifattach(ifp);
if (ifp->if_sadl) {
::free(ifp->if_sadl);
}
ifp->if_sadl = (struct sockaddr_dl *)::malloc(sizeof(struct sockaddr_dl), 0, 0);
memcpy(LLADDR(ifp->if_sadl), ic->ic_myaddr, ETHER_ADDR_LEN);

ifp->if_output = ieee80211_output;

Expand Down Expand Up @@ -280,6 +285,9 @@ ieee80211_ifdetach(struct _ifnet *ifp)
ifp->if_slowtimo->release();
ifp->if_slowtimo = NULL;
}
if (ifp->if_sadl) {
::free(ifp->if_sadl);
}
ifp->netStat = NULL;
ifp->controller = NULL;
ifp->output_queue = NULL;
Expand Down
10 changes: 8 additions & 2 deletions itl80211/openbsd/net80211/ieee80211_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,14 @@ ieee80211_ioctl_setnwkeys(struct ieee80211com *ic,
error = kernel_copyin((const user_addr_t)nwkey->i_key[i].i_keydat, k->k_key, k->k_len);
if (error != 0)
return error;
if ((error = (*ic->ic_set_key)(ic, NULL, k)) != 0)
return error;
error = (*ic->ic_set_key)(ic, NULL, k);
switch (error) {
case 0:
case EBUSY:
break;
default:
return error;
}
}

ic->ic_def_txkey = nwkey->i_defkid - 1;
Expand Down
94 changes: 65 additions & 29 deletions itl80211/openbsd/net80211/ieee80211_pae_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ ieee80211_recv_4way_msg3(struct ieee80211com *ic,
const u_int8_t *frm, *efrm;
const u_int8_t *rsnie1, *rsnie2, *gtk, *igtk;
u_int16_t info, reason = 0;
int keylen;
int keylen, deferlink = 0;

#ifndef IEEE80211_STA_ONLY
if (ic->ic_opmode != IEEE80211_M_STA &&
Expand Down Expand Up @@ -584,9 +584,15 @@ ieee80211_recv_4way_msg3(struct ieee80211com *ic,
k->k_len = keylen;
memcpy(k->k_key, ni->ni_ptk.tk, k->k_len);
/* install the PTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
break;
case EBUSY:
deferlink = 1;
break;
default:
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
}
ni->ni_flags &= ~IEEE80211_NODE_RSN_NEW_PTK;
ni->ni_flags &= ~IEEE80211_NODE_TXRXPROT;
Expand Down Expand Up @@ -620,7 +626,13 @@ ieee80211_recv_4way_msg3(struct ieee80211com *ic,
k->k_len = keylen;
memcpy(k->k_key, &gtk[8], k->k_len);
/* install the GTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
break;
case EBUSY:
deferlink = 1;
break;
default:
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
}
Expand Down Expand Up @@ -651,9 +663,15 @@ ieee80211_recv_4way_msg3(struct ieee80211com *ic,
k->k_len = 16;
memcpy(k->k_key, &igtk[14], k->k_len);
/* install the IGTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
break;
case EBUSY:
deferlink = 1;
break;
default:
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
}
}
}
Expand All @@ -667,10 +685,12 @@ ieee80211_recv_4way_msg3(struct ieee80211com *ic,
++ni->ni_key_count == 2)
#endif
{
DPRINTF(("marking port %s valid\n",
ether_sprintf(ni->ni_macaddr)));
ni->ni_port_valid = 1;
ieee80211_set_link_state(ic, LINK_STATE_UP);
if (deferlink == 0) {
DPRINTF(("marking port %s valid\n",
ether_sprintf(ni->ni_macaddr)));
ni->ni_port_valid = 1;
ieee80211_set_link_state(ic, LINK_STATE_UP);
}
ni->ni_assoc_fail = 0;
if (ic->ic_opmode == IEEE80211_M_STA)
ic->ic_rsngroupcipher = ni->ni_rsngroupcipher;
Expand Down Expand Up @@ -726,12 +746,16 @@ ieee80211_recv_4way_msg4(struct ieee80211com *ic,
k->k_len = ieee80211_cipher_keylen(k->k_cipher);
memcpy(k->k_key, ni->ni_ptk.tk, k->k_len);
/* install the PTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
IEEE80211_SEND_MGMT(ic, ni,
IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_ASSOC_TOOMANY);
ieee80211_node_leave(ic, ni);
return;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
case EBUSY:
break;
default:
IEEE80211_SEND_MGMT(ic, ni,
IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_ASSOC_TOOMANY);
ieee80211_node_leave(ic, ni);
return;
}
ni->ni_flags |= IEEE80211_NODE_TXRXPROT;
}
Expand Down Expand Up @@ -898,9 +922,13 @@ ieee80211_recv_rsn_group_msg1(struct ieee80211com *ic,
k->k_len = keylen;
memcpy(k->k_key, &gtk[8], k->k_len);
/* install the GTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
case EBUSY:
break;
default:
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
}
}
if (igtk != NULL) { /* implies MFP */
Expand All @@ -926,9 +954,13 @@ ieee80211_recv_rsn_group_msg1(struct ieee80211com *ic,
k->k_len = 16;
memcpy(k->k_key, &igtk[14], k->k_len);
/* install the IGTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
case EBUSY:
break;
default:
reason = IEEE80211_REASON_AUTH_LEAVE;
goto deauth;
}
}
}
Expand Down Expand Up @@ -1031,11 +1063,15 @@ ieee80211_recv_wpa_group_msg1(struct ieee80211com *ic,
k->k_len = keylen;
memcpy(k->k_key, gtk, k->k_len);
/* install the GTK */
if ((*ic->ic_set_key)(ic, ni, k) != 0) {
IEEE80211_SEND_MGMT(ic, ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_AUTH_LEAVE);
ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
return;
switch ((*ic->ic_set_key)(ic, ni, k)) {
case 0:
case EBUSY:
break;
default:
IEEE80211_SEND_MGMT(ic, ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
IEEE80211_REASON_AUTH_LEAVE);
ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
return;
}
}
if (info & EAPOL_KEY_SECURE) {
Expand Down
21 changes: 16 additions & 5 deletions itl80211/openbsd/net80211/ieee80211_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,26 @@ ieee80211_setkeysdone(struct ieee80211com *ic)

/* install GTK */
kid = (ic->ic_def_txkey == 1) ? 2 : 1;
if ((*ic->ic_set_key)(ic, ic->ic_bss, &ic->ic_nw_keys[kid]) == 0)
ic->ic_def_txkey = kid;
switch ((*ic->ic_set_key)(ic, ic->ic_bss, &ic->ic_nw_keys[kid])) {
case 0:
case EBUSY:
ic->ic_def_txkey = kid;
break;
default:
break;
}

if (ic->ic_caps & IEEE80211_C_MFP) {
/* install IGTK */
kid = (ic->ic_igtk_kid == 4) ? 5 : 4;
if ((*ic->ic_set_key)(ic, ic->ic_bss,
&ic->ic_nw_keys[kid]) == 0)
ic->ic_igtk_kid = kid;
switch ((*ic->ic_set_key)(ic, ic->ic_bss, &ic->ic_nw_keys[kid])) {
case 0:
case EBUSY:
ic->ic_igtk_kid = kid;
break;
default:
break;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions itl80211/openbsd/net80211/timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ int timeout_pending(CTimeout **to)
return _fCommandGate->runAction(&CTimeout::timeout_pending, to) == kIOReturnSuccess ? 1 : 0;
}

int timeout_initialized(CTimeout **to)
{
return (*to) != NULL;
}

#endif /* timeout_cpp */
7 changes: 7 additions & 0 deletions itl80211/openbsd/sys/_if_ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,11 @@ if_attach(struct _ifnet *ifp)
return 0;
}

static inline int
if_detach(struct _ifnet *ifp)
{
ifp->if_link_state = -1;
return 0;
}

#endif /* _if_ether_h */
6 changes: 6 additions & 0 deletions itl80211/openbsd/sys/_ifq.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ ifq_is_oactive(IOPacketQueue **ifq)
return (ifq_oactive);
}

static inline mbuf_t
ifq_dequeue(IOPacketQueue **ifq)
{
return (*ifq)->lockDequeue();
}

#endif /* _ifq_h */
2 changes: 2 additions & 0 deletions itl80211/openbsd/sys/timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ int timeout_del(CTimeout **to);
int timeout_pending(CTimeout **to);
int timeout_free(CTimeout **to);

int timeout_initialized(CTimeout **to);

#endif /* _SYS_TIMEOUT_H_ */
44 changes: 20 additions & 24 deletions itlwm/itlwm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ class itlwm : public IOEthernetController {
public:

//kext
bool init(OSDictionary *properties) override;
void free() override;
IOService* probe(IOService* provider, SInt32* score) override;
bool start(IOService *provider) override;
void stop(IOService *provider) override;
IOReturn getHardwareAddress(IOEthernetAddress* addrP) override;
IOReturn enable(IONetworkInterface *netif) override;
IOReturn disable(IONetworkInterface *netif) override;
UInt32 outputPacket(mbuf_t, void * param) override;
IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode) override;
IOReturn setMulticastMode(IOEnetMulticastMode mode) override;
IOReturn setMulticastList(IOEthernetAddress* addr, UInt32 len) override;
bool configureInterface(IONetworkInterface *netif) override;
virtual bool init(OSDictionary *properties) override;
virtual void free() override;
virtual IOService* probe(IOService* provider, SInt32* score) override;
virtual bool start(IOService *provider) override;
virtual void stop(IOService *provider) override;
virtual IOReturn getHardwareAddress(IOEthernetAddress* addrP) override;
virtual IOReturn enable(IONetworkInterface *netif) override;
virtual IOReturn disable(IONetworkInterface *netif) override;
virtual UInt32 outputPacket(mbuf_t, void * param) override;
virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode) override;
virtual IOReturn setMulticastMode(IOEnetMulticastMode mode) override;
virtual IOReturn setMulticastList(IOEthernetAddress* addr, UInt32 len) override;
virtual bool configureInterface(IONetworkInterface *netif) override;
virtual bool createWorkLoop() override;
virtual IOWorkLoop* getWorkLoop() const override;
virtual const OSString * newVendorString() const override;
Expand All @@ -73,6 +73,13 @@ class itlwm : public IOEthernetController {
#ifdef __PRIVATE_SPI__
virtual IOReturn outputStart(IONetworkInterface *interface, IOOptionBits options) override;
#endif
virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters) const override;
virtual IOReturn selectMedium(const IONetworkMedium *medium) override;
virtual UInt32 getFeatures() const override;
virtual IOReturn registerWithPolicyMaker( IOService * policyMaker ) override;
virtual IOReturn setPowerState( unsigned long powerStateOrdinal,
IOService * policyMaker) override;
virtual IOReturn setWakeOnMagicPacket( bool active ) override;

void releaseAll();
void joinSSID(const char *ssid, const char *pwd);
Expand All @@ -85,22 +92,11 @@ class itlwm : public IOEthernetController {
IOEthernetInterface *getNetworkInterface();

static IOReturn tsleepHandler(OSObject* owner, void* arg0 = 0, void* arg1 = 0, void* arg2 = 0, void* arg3 = 0);

//-----------------------------------------------------------------------
// Power management support.
//-----------------------------------------------------------------------
virtual IOReturn registerWithPolicyMaker( IOService * policyMaker ) override;
virtual IOReturn setPowerState( unsigned long powerStateOrdinal,
IOService * policyMaker) override;
virtual IOReturn setWakeOnMagicPacket( bool active ) override;
void setPowerStateOff(void);
void setPowerStateOn(void);
void unregistPM();

bool createMediumTables(const IONetworkMedium **primary);
virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters) const override;
virtual IOReturn selectMedium(const IONetworkMedium *medium) override;
virtual UInt32 getFeatures() const override;

public:
IOInterruptEventSource* fInterrupt;
Expand Down

0 comments on commit c2f2c51

Please sign in to comment.