http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/scan.c?id=v3.17#n1130.

    Positional arguments:
    data -- bytearray data to read.

    Returns:
    Dict.

def get_wifi_wps(_, data):
    """http://git.kernel.org/cgit/linux/kernel/git/jberg/iw.git/tree/scan.c?id=v3.17#n1130.

    Positional arguments:
    data -- bytearray data to read.

    Returns:
    Dict.
    """
    answers = dict()
    while len(data) >= 4:
        subtype = (data[0] << 8) + data[1]
        sublen = (data[2] << 8) + data[3]
        if sublen > len(data):
            break
        elif subtype == 0x104a:
            answers['Version'] = data[4] >> 4, data[4] & 0xF
        elif subtype == 0x1011:
            answers['Device name'] = data[4:sublen + 4]
        elif subtype == 0x1012:
            if sublen != 2:
                answers['Device Password ID'] = 'invalid length %d'.format(sublen)
            else:
                id_ = data[4] << 8 | data[5]
                answers['Device Password ID'] = (id_, wifi_wps_dev_passwd_id(id_))
        elif subtype == 0x1021:
            answers['Manufacturer'] = data[4:sublen + 4]
        elif subtype == 0x1023:
            answers['Model'] = data[4:sublen + 4]
        elif subtype == 0x1024:
            answers['Model Number'] = data[4:sublen + 4]
        elif subtype == 0x103b:
            val = data[4]
            answers['Response Type'] = (val, 'AP' if val == 3 else '')
        elif subtype == 0x103c:
            answers['RF Bands'] = data[4]
        elif subtype == 0x1041:
            answers['Selected Registrar'] = data[4]
        elif subtype == 0x1042:
            answers['Serial Number'] = data[4:sublen + 4]
        elif subtype == 0x1044:
            val = data[4]
            answers['Wi-Fi Protected Setup State'] = (val, {1: 'Unconfigured', 2: 'Configured'}.get(val, ''))
        elif subtype == 0x1047:
            if sublen != 16:
                answers['UUID'] = '(invalid, length={0})'.format(sublen)
            else:
                answers['UUID'] = bytearray(data[4:19])
        elif subtype == 0x1054:
            if sublen != 8:
                answers['Primary Device Type'] = '(invalid, length={0})'.format(sublen)
            else:
                answers['Primary Device Type'] = '{0}-{1}-{2}'.format(
                    data[4] << 8 | data[5],
                    ''.join(format(x, '02x') for x in data[6:9]),
                    data[10] << 8 | data[11]
                )
        elif subtype == 0x1057:
            answers['AP setup locked'] = data[4]
        elif subtype == 0x1008 or subtype == 0x1053:
            meth = (data[4] << 8) + data[5]
            key = 'Selected Registrar Config methods' if subtype == 0x1053 else 'Config methods'
            values = [s for i, s in enumerate(('USB', 'Ethernet', 'Label', 'Display', 'Ext. NFC', 'Int. NFC',
                                               'NFC Intf.', 'PBC', 'Keypad')) if meth & (1 << i)]
            answers[key] = values
        else:
            value = ' '.join(format(x, '02x') for x in data[4:])
            answers['Unknown TLV ({0:04x}, {1} bytes)'.format(subtype, sublen)] = value
        data = data[4:]
    if data:
        answers['bogus tail data'] = ' '.join(format(x, '02x') for x in data)
    return answers