From 669818a9736e8025eb5b13ff534bd3fcf3d812aa Mon Sep 17 00:00:00 2001 From: WraithWireless Date: Sun, 26 Jun 2016 09:48:49 -0600 Subject: [PATCH] v0.1.4 updated to support linux kernel v 4 --- TODO | 33 ++++++++++++--------------------- pyric/net/wireless/nl80211_h.py | 2 +- pyric/pyw.py | 10 +++++----- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/TODO b/TODO index 4a15a21..1e5bc84 100644 --- a/TODO +++ b/TODO @@ -4,11 +4,7 @@ 3) parse NL80211_ATTR_WIPHY_BANDS (have workaround currently in place) - after figuring out _CIPHER_SUITES, may be able to get a solution for the bands 4) RFI (1) -5) Should we move to netlink for setting ip address? - - ioctl allows us to set erroneous values for netmask, broadcast whereas netlink - forces validity 6) find a better way to get supported standards of a card -7) code up txget, txset via netlink even though cards don't seem to support it 8) Two commands that would add information of minor value o ethtool. uses ioctl but does not follow same pattern as ifconfig seems to use @@ -109,18 +105,17 @@ error strings and test for NLE_SUCCESS in netlink error message 6) Setting the channel/Frequency nl80211.h states that using NL80211_CMD_SET_WIPHY to set the channel is deprecated in place of NL80211_CMD_SET_CHANNEL. Below is the attempted code: -phy = devinfoex(nlsock,nic)['phy'] -msg = nl.nlmsg_new(nl_type=_FAM80211ID_, - cmd=nl80211h.NL80211_CMD_SET_CHANNEL, - flags=nlh.NLM_F_REQUEST | nlh.NLM_F_ACK) -msg.nla_put_u32(phy,nl80211h.NL80211_ATTR_WIPHY) -msg.nla_put_u32(channels.ch2rf(ch),nl80211h.NL80211_ATTR_WIPHY_FREQ) -msg.nla_put_u32(CHWIDTHS.index(chw),nl80211h.NL80211_ATTR_WIPHY_CHANNEL_TYPE) - -# Here as found during updating nl80211.h, _CHANNEL_TYPE is not CHANNEL_WIDTH - -and results in a 'invalid argument' error. So, am I sending the wrong crap? The -description for this command in nl80211_h +msg = nl.nlmsg_new(nltype=_familyid_(nlsock), + cmd=nl80211h.NL80211_CMD_SET_CHANNEL, + flags=nlh.NLM_F_REQUEST | nlh.NLM_F_ACK) + nl.nla_put_u32(msg, card.idx, nl80211h.NL80211_ATTR_IFINDEX) + nl.nla_put_u32(msg, channels.ch2rf(ch), nl80211h.NL80211_ATTR_WIPHY_FREQ) + nl.nla_put_u32(msg, channels.CHTYPES.index(chw), nl80211h.NL80211_ATTR_WIPHY_CHANNEL_TYPE) + nl.nl_sendmsg(nlsock, msg) + nl.nl_recvmsg(nlsock) + +and results in a 'Operation not supported' error. +The description for this command in nl80211_h * @NL80211_CMD_SET_CHANNEL: Set the channel (using %NL80211_ATTR_WIPHY_FREQ * and the attributes determining channel width) the given interface @@ -132,11 +127,7 @@ description for this command in nl80211_h * of any other interfaces, and other interfaces will again take * precedence when they are used. -mentions ifindex. Adding the ifindex with: - -msg.nla_put_u32(nl80211h.NL80211_ATTR_IFINDEX,8) - -still gives an 'invalid argument' error. Took out channel width and still no go +This works if the card is in monitor mode * workaround in place, using the deprecated NL80211_CMD_SET_WIPHY diff --git a/pyric/net/wireless/nl80211_h.py b/pyric/net/wireless/nl80211_h.py index 545d195..8af48f7 100644 --- a/pyric/net/wireless/nl80211_h.py +++ b/pyric/net/wireless/nl80211_h.py @@ -422,7 +422,7 @@ * mesh config parameters may be given. * @NL80211_CMD_LEAVE_MESH: Leave the mesh network -- no special arguments, the * network is determined by the network interface. - * @NL80211_CMD_UNPROT_DEAUTHENTICATE: Unprotected deauthentication frame + * @NL80211_CMD_UNPR_OT_DEAUTHENTICATE: Unprotected deauthentication frame * notification. This event is used to indicate that an unprotected * deauthentication frame was dropped when MFP is in use. * @NL80211_CMD_UNPROT_DISASSOCIATE: Unprotected disassociation frame diff --git a/pyric/pyw.py b/pyric/pyw.py index 66114f6..5841a08 100644 --- a/pyric/pyw.py +++ b/pyric/pyw.py @@ -1291,7 +1291,6 @@ def chset(card, ch, chw=None, *argv): device's channels to be changed """ if ch not in channels.channels(): raise pyric.error(errno.EINVAL, "Invalid channel") - if chw not in channels.CHTYPES: raise pyric.error(errno.EINVAL, "Invalid width") try: nlsock = argv[0] @@ -1310,7 +1309,8 @@ def freqset(card, rf, chw=None, *argv): :param argv: netlink socket at argv[0] (or empty) """ if rf not in channels.freqs(): raise pyric.error(errno.EINVAL, "Invalid frequency") - if chw not in channels.CHTYPES: raise pyric.error(errno.EINVAL, "Invalid width") + if chw in channels.CHTYPES: chw = channels.CHTYPES.index(chw) + else: raise pyric.error(errno.EINVAL, "Invalid width") try: nlsock = argv[0] @@ -1323,8 +1323,7 @@ def freqset(card, rf, chw=None, *argv): flags=nlh.NLM_F_REQUEST | nlh.NLM_F_ACK) nl.nla_put_u32(msg, card.phy, nl80211h.NL80211_ATTR_WIPHY) nl.nla_put_u32(msg, rf, nl80211h.NL80211_ATTR_WIPHY_FREQ) - nl.nla_put_u32(msg, channels.CHTYPES.index(chw), - nl80211h.NL80211_ATTR_WIPHY_CHANNEL_TYPE) + nl.nla_put_u32(msg, chw, nl80211h.NL80211_ATTR_WIPHY_CHANNEL_TYPE) nl.nl_sendmsg(nlsock, msg) nl.nl_recvmsg(nlsock) except AttributeError: @@ -1777,6 +1776,7 @@ def _fut_chset(card, ch, chw, *argv): :param argv: netlink socket at argv[0] (or empty) uses the newer NL80211_CMD_SET_CHANNEL vice iw's depecrated version which uses *_SET_WIPHY however, ATT does not work raise Errno 22 Invalid Argument + NOTE: This only works for cards in monitor mode """ if ch not in channels.channels(): raise pyric.error(errno.EINVAL, "Invalid channel") if chw not in channels.CHTYPES: raise pyric.error(errno.EINVAL, "Invalid channel width") @@ -1788,7 +1788,7 @@ def _fut_chset(card, ch, chw, *argv): msg = nl.nlmsg_new(nltype=_familyid_(nlsock), cmd=nl80211h.NL80211_CMD_SET_CHANNEL, flags=nlh.NLM_F_REQUEST | nlh.NLM_F_ACK) - nl.nla_put_u32(msg, card.phy, nl80211h.NL80211_ATTR_WIPHY) + nl.nla_put_u32(msg, card.idx, nl80211h.NL80211_ATTR_IFINDEX) nl.nla_put_u32(msg, channels.ch2rf(ch), nl80211h.NL80211_ATTR_WIPHY_FREQ) nl.nla_put_u32(msg, channels.CHTYPES.index(chw), nl80211h.NL80211_ATTR_WIPHY_CHANNEL_TYPE) nl.nl_sendmsg(nlsock, msg)