Code Monkey home page Code Monkey logo

itamae's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

itamae's Issues

Parsing 802.11n MCS

Hi,
I think there is a problem when parsing 802.11n data rate. Although the 3 Bytes for mcs are retrieved correctly, when I call

dR2 = rtap.parse(raw2)
dR2.rate

it gives me slightly different rate than when I parse the same packets with wireshark.

I use ath10k and

iw mon0 set freq 5180 80 5210

and monitor my mobile phone traffic.

I tracked the problem to your code in mcs.py and I noticed that in your MCS_HT_RATES list you might have put the Guard Interval bits in different order.

By having a look here http://mcsindex.com/ and here http://www.radiotap.org/fields/MCS.html we know that if for example this 07 05 07 is the hex representation of MCS field, from the second Byte we get that Bandwidth is 40(2 least significant bits) and from the 3d bit we get "1" which means GI=short GI. From the third Byte we get mcs_index = 7.

Now in your mcs_rate() function the 7th element from the list is called
{20:{1:65,0:72.2},40:{1:135,0:150}}, # mcs index 7
with bandwidth 40 and guard interval 1 which points to 135 instead of 150 as the rate should be based on mcsindex.com --> Data Rate SGI = 400ns 40MHZ mcs index 7 = 150

Python3 support

I have some issues:


data:3d2118a6f711e7b90000000000000000000000000000000000000000000000000000000000000b000080020000000040000000ffffffffffff3ea659ce780bffffffffffff40570000010802040b160c12182432043048606c03010b2d1a7e0113ff00000001000000000000000100000000000000000000


ERROR:asyncio:Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 973, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "radar-server.py", line 62, in datagram_received
    dR1,DM1,l3,err = sushi.bento(data[36:])
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/sushi.py", line 51, in bento
    dM = mpdu.parse(f[dR.size:],'fcs' in dR.flags)
TypeError: argument of type 'NoneType' is not iterable


data:3d2118a6f711e7b900000000000000000000000000000000000000000000000000000000000018002e4000a02008000000026c09a000b9000000b90040000000ffffffffffffdaa1198def87fffffffffffff0820000010402040b1632080c1218243048606c0301012d1a6e0103ff00000000000000000000000000000000000000000000dd070050f2080001007f0500000a0201


ERROR:asyncio:Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 973, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "radar-server.py", line 62, in datagram_received
    dR1,DM1,l3,err = sushi.bento(data[36:])
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/sushi.py", line 51, in bento
    dM = mpdu.parse(f[dR.size:],'fcs' in dR.flags)
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/mpdu.py", line 299, in parse
    if m.type == std.FT_MGMT: _mpdu._parsemgmt_(f,m)
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/_mpdu.py", line 414, in _parsemgmt_
    ie = _parseie_(eid,ie)
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/_mpdu.py", line 465, in _parseie_
    info = [_eidrates_(struct.unpack('=B',r)[0]) for r in info]
  File "/home/radar/.local/lib/python3.7/site-packages/itamae/_mpdu.py", line 465, in <listcomp>
    info = [_eidrates_(struct.unpack('=B',r)[0]) for r in info]
TypeError: a bytes-like object is required, not 'int'

Get lots of errors when parsing packets suffered from ESP8266

I'm using this tool to get packets that processed by ESP8266 MAC Layer with the help of this tool (https://github.com/ernacktob/esp8266_wifi_raw/).

However, I got many errors when parsing these packets with mpdu.parse

for example, first line is the packet and second line is the result.

80000000fffffffffffffcb698f61380fcb698f61380e0a78081362feb0100002c01211400075748552d535455010882840b160c1218240301010504000100010706434e20010d142a010032043048606c460571000000002d1a8c0103ffff0000000000000000000001000000000000000000003d16010005000000000000000000000000000000000000007f080000080000000440dd180050f2020101030003a4000027a4000042435e0062322f00dd0900037f01010000ff7f00004243
{'info-elements': {0: [u'WHU-STU', u''], 3: [1], 5: [{'dtim-cnt': 0, 'bm-ctrl': {'tib': 0, 'offset': 0}, 'dtim-per': 1, 'vir-bm': '01'}], 7: [{'country': bytearray(b'CN '), 'op-tuples': [(67, 78, 32), (1, 13, 20)]}], 42: [{'use-protect': 0, 'barker': 0, 'non-erp': 0, 'rsrv': 0}], 45: [{'ht-info': {'ch-width-set': 0, '40-intolerant': 0, 'dsss-cck-mod': 0, 'rsrv': 0, 'ldpc-cap': 0, 'lsig-txop-pro': 0, 'max-amsdu': 0, 'tx-stbc': 1, 'short-gi-40': 0, 'rx-stbc': 1, 'short-gi-20': 0, 'ht-greenfield': 0, 'ht-delay-back': 0, 'sm-pwr-save': 3}, 'ampdu-param': {'max-length': 3, 'min-spacing': 0, 'rsrv': 0}, 'asel-cap': {'ant-cap': 0, 'tx-ppdu-cap': 0, 'rsrv': 0, 'ant-asel-cap': 0, 'recv-asel-cap': 0, 'csi-asel-cap': 0, 'ant-sel': 0, 'csi-cap': 0}, 'tx-beamform': {'rx-stag-sound': 0, 'tx-csi-feedback': 0, 'rsrv': 0, 'calibration': 0, 'rx-ndp': 0, 'csi-tx': 0, 'noncompressed-feedback': 0, 'compressed-feedback': 0, 'comp-antenna': 0, 'csi-max-rows': 0, 'csi-antenna': 0, 'tx-bf-cap': 0, 'rx-cap': 0, 'compressed': 0, 'tx-stag-sound': 0, 'noncomp-antenna': 0, 'tx-ndp': 0, 'ch-est-cap': 0, 'min-grouping': 0, 'noncompressed': 0}, 'mcs-set': {'tx-max-num-spatial': 0, 'tx/rx-mcs-set-unequal': 0, 'tx-highest-sup-data-rate': 0, 'tx-ms-set-defined': 1, 'tx-unequal-mod': 0, 'rx-mcs-bitmask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'rsrv-1': 0, 'rsrv-2': 0, 'rsrv-3': 0}, 'ht-ext-cap': {'+htc': 0, 'mcs-feedback': 0, 'rd-resp': 0, 'pco': 0, 'rsrv-1': 0, 'rsrv-2': 0, 'pco-transit': 0}}], 221: [{'content': bytearray(b"\x02\x01\x01\x03\x00\x03\xa4\x00\x00\'\xa4\x00\x00BC^\x00b2/\x00"), 'oui': '00:50:f2'}, {'content': bytearray(b'\x01\x01\x00\x00\xff\x7f'), 'oui': '00:03:7f'}], 61: [{'mcs-set': {'tx-max-num-spatial': 0, 'tx/rx-mcs-set-unequal': 0, 'tx-highest-sup-data-rate': 0, 'tx-ms-set-defined': 0, 'tx-unequal-mod': 0, 'rx-mcs-bitmask': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'rsrv-1': 0, 'rsrv-2': 0, 'rsrv-3': 0}, 'ht-op-info': {'pco-phase': 0, 'non-greenfield': 1, 'sta-ch-width': 0, 'rifs': 0, 'obss-non-ht': 0, 'lsig-txop-pro': 0, 'dual-cts': 0, 'ht-pro': 1, 'dual-beacon': 0, 'stbc-beacon': 0, 'pco-active': 0, 'rsrv-4': 0, 'rsrv-5': 0, 'sec-ch-off': 0, 'rsrv-1': 0, 'rsrv-2': 0, 'rsrv-3': 0}, 'pri-ch': 1}]}, 'err': [('mgmt.info-elements.eid-1', "parsing <type 'exceptions.RuntimeError'>-unpack requires a string argument of length 1"), ('mgmt.info-elements.eid-50', "parsing <type 'exceptions.RuntimeError'>-unpack requires a string argument of length 1"), ('mgmt.info-elements.eid-70', "parsing <type 'exceptions.TypeError'>-an integer is required"), ('mgmt.info-elements.eid-127', "parsing <type 'exceptions.EnvironmentError'>-[Errno 127] subelement has length"), ('mgmt.info-elements.eid-66', "parsing <type 'exceptions.RuntimeError'>-unpack requires a string argument of length 1")], 'stripped': 0, 'addr1': 'ff:ff:ff:ff:ff:ff', 'seqctrl': {'seqno': 2686, 'fragno': 0}, 'fixed-params': {'capability': {'rdo-meas': 1, 'dsss-ofdm': 0, 'cfpollable': 0, 'ess': 1, 'privacy': 0, 'ibss': 0, 'ch-agility': 0, 'immediate-ba': 0, 'spec-mgmt': 0, 'time-slot': 1, 'pbcc': 0, 'cf-poll-req': 0, 'delayed-ba': 0, 'short-pre': 1, 'apsd': 0, 'qos': 0}, 'timestamp': 2109621043584L, 'beacon-int': 307200}, 'addr2': 'fc:b6:98:f6:13:80', 'addr3': 'fc:b6:98:f6:13:80', 'offset': 258, 'duration': {'dur': 0, 'type': 'vcs'}, 'framectrl': {'subtype': 8, 'vers': 0, 'type': 0, 'flags': {'md': 0, 'mf': 0, 'o': 0, 'r': 0, 'fd': 0, 'pf': 0, 'td': 0, 'pm': 0}}, 'present': ['framectrl', 'duration', 'addr1', 'addr2', 'addr3', 'seqctrl', 'fixed-params', 'info-elements']}

I'm not sure if it's the problem during my packet sniffing or parsing.

By the way, In _mpdu.py#417 the except RuntimeError should be except RuntimeError as e: or except Exception as e:. otherwise it will crash directly with the input.

This is the code I'm using and the data I collected.
https://gist.github.com/Yangff/7f88e7503ce15e8bc8a7c4b1a06ca5f2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.