Ejemplo n.º 1
0
def main():
    iid = int(sys.argv[1], 0)
    buf_id = int(sys.argv[2], 0)

    with Controller() as ctrl:
        offset = 0
        readlen = 0x20
        buffer = bytes()
        while True:
            try:
                print(f"reading {offset}:{readlen}")
                data = ctrl.request(build_command(iid, buf_id, offset,
                                                  readlen))
            except TimeoutError:
                continue

            (_, _, nread, end), bufdata = unpack_buffer(data)
            print(f"read {offset}:{nread}")
            buffer += bufdata
            offset += nread

            if end != 0:
                break

    out = open(f"tclbuf_iid{iid}_bufid{buf_id}.bin", "wb")
    out.write(buffer)
def cmd_disable():
    if len(sys.argv) != 9:
        print("Error: Invalid number of parameters")
        sys.exit(0)

    evdesc = parse_event_descriptor(sys.argv[2:9])

    with Controller() as ctrl:
        ctrl.event_disable(evdesc)
def cmd_listen(as_json=False):
    if len(sys.argv) != 3:
        print("Error: Invalid number of parameters")
        sys.exit(0)

    categories = sys.argv[2].split(',')
    categories = [int(x, base=16) for x in categories]

    with Controller() as ctrl:
        for x in categories:
            ctrl.notifier_register(x)

        while True:
            if as_json:
                print(json.dumps(ctrl.read_event().to_dict()))
            else:
                print(ctrl.read_event())
Ejemplo n.º 4
0
def main():
    if len(sys.argv) != 2:
        print_usage_and_exit()

    cmd = sys.argv[1]

    if cmd == "help":
        print_help_and_exit()

    rqst = COMMANDS.get(cmd)

    if rqst is None:
        print(f"Invalid command: '{sys.argv[1]}'")
        print(f"")
        print_usage_and_exit()

    with Controller() as ctrl:
        rsp = ctrl.request(rqst)
        if rsp:
            print(' '.join(['{:02x}'.format(x) for x in rsp]))
Ejemplo n.º 5
0
def main():
    cmd_name = sys.argv[1]

    if cmd_name == 'help':
        print(f'Usage:')
        print(f'  {sys.argv[0]} <command> [args...]')
        print(f'')
        print(f'Commands:')
        print(f'  help')
        print(f'    display this help message')
        print(f'')
        print(f'  request <tc> <tid> <cid> <iid> <flags> [payload...]')
        print(f'    basic command with optional payload')
        print(f'')
        print(f'Arguments:')
        print(f'  <tc>:          command target category')
        print(f'  <tid>:         command target ID')
        print(f'  <cid>:         command ID')
        print(f'  <iid>:         command instance ID')
        print(f'  <flags>:       request flags')
        print(
            f'  [payload...]:  optional payload bytes, separated by whitespace'
        )

    elif cmd_name == 'request':
        tc = int(sys.argv[2], 0)
        tid = int(sys.argv[3], 0)
        cid = int(sys.argv[4], 0)
        iid = int(sys.argv[5], 0)
        flg = int(sys.argv[6], 0)
        pld = [int(x, 0) for x in sys.argv[7:]]

        rqst = Request(tc, tid, cid, iid, flg, pld)

        with Controller() as ctrl:
            rsp = ctrl.request(rqst)
            if rsp:
                print(' '.join(['{:02x}'.format(x) for x in rsp]))
Ejemplo n.º 6
0
def main():
    requests = [
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x00,
            "bufid": 0x00
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x00,
            "bufid": 0x01
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x00,
            "bufid": 0x02
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x00,
            "bufid": 0x03
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x01,
            "bufid": 0x00
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x01,
            "bufid": 0x01
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x01,
            "bufid": 0x02
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x01,
            "bufid": 0x03
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x02,
            "bufid": 0x00
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x02,
            "bufid": 0x01
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x02,
            "bufid": 0x02
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x02,
            "bufid": 0x03
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x03,
            "bufid": 0x00
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x03,
            "bufid": 0x01
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x03,
            "bufid": 0x02
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x03,
            "bufid": 0x03
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x04,
            "bufid": 0x00
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x04,
            "bufid": 0x01
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x04,
            "bufid": 0x02
        },
        {
            "tc": 0x15,
            "tid": 0x02,
            "cid": 0x04,
            "iid": 0x04,
            "bufid": 0x03
        },
    ]

    with Controller() as ctrl:
        output = []
        for rq in requests:
            try:
                data = query_buffer(ctrl, **rq)

                rq["response"] = [x for x in data]
                output += [rq]
            except OSError as e:
                eprint(f"Failed to execute request: {rq} ({e})")

    print(json.dumps(output))
Ejemplo n.º 7
0
def main():
    cmd_name = sys.argv[1]

    if cmd_name == 'help':
        print(f'Usage:')
        print(f'  {sys.argv[0]} <command> [args...]')
        print(f'')
        print(f'Commands:')
        print(f'  help')
        print(f'    display this help message')
        print(f'')
        print(f'  legacy-get-descriptor <entry>')
        print(f'    get the HID device descriptor identified by <entry>')
        print(f'')
        print(f'    <entry>:  0  HID descriptor')
        print(f'              1  HID report descriptor')
        print(f'              2  device attributes')
        print(f'')
        print(f'  legacy-get-feature-report <num>')
        print(f'    get the HID feature report identified by <num>')
        print(f'')
        print(f'  legacy-set-capslock-led <state>')
        print(f'    set the capslock led state')
        print(f'')
        print(f'  hid-get-descriptor <tid> <iid> <entry>')
        print(f'    get the HID device descriptor identified by <entry>')
        print(f'    for device instance with ID <iid>')
        print(f'')
        print(f'    <entry>:  0  HID descriptor')
        print(f'              1  HID report descriptor')
        print(f'              2  device attributes')

    elif cmd_name == 'legacy-get-descriptor':
        entry = int(sys.argv[2], 0)

        with Controller() as ctrl:
            dev = SurfaceLegacyKeyboard(ctrl)
            dump_raw_data(dev.get_device_descriptor(entry))

    elif cmd_name == 'legacy-get-feature-report':
        num = int(sys.argv[2], 0)

        with Controller() as ctrl:
            dev = SurfaceLegacyKeyboard(ctrl)
            dump_raw_data(dev.get_hid_feature_report(num))

    elif cmd_name == 'legacy-set-capslock-led':
        state = int(sys.argv[2], 0)

        with Controller() as ctrl:
            dev = SurfaceLegacyKeyboard(ctrl)
            dev.set_capslock_led(state)

    elif cmd_name == 'hid-get-descriptor':
        tid = int(sys.argv[2], 0)
        iid = int(sys.argv[3], 0)
        entry = int(sys.argv[4], 0)

        with Controller() as ctrl:
            dev = SurfaceHidDevice(ctrl, tid, iid)
            dump_raw_data(dev.get_device_descriptor(entry))

    else:
        print(f'Invalid command: \'{cmd_name}\', try \'{sys.argv[0]} help\'')
        sys.exit(1)
Ejemplo n.º 8
0
def run_command(rqst):
    with Controller() as ctrl:
        data = ctrl.request(rqst)
        if data:
            print(' '.join(['{:02x}'.format(x) for x in data]))