Sylvain Munaut | caf8cf9 | 2022-01-12 13:35:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * usb_dev.c |
| 3 | * |
| 4 | * Copyright (C) 2019-2022 Sylvain Munaut <tnt@246tNt.com> |
| 5 | * SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include <stdint.h> |
Sylvain Munaut | 2c33f6d | 2022-01-12 14:12:31 +0100 | [diff] [blame] | 9 | #include <string.h> |
Sylvain Munaut | caf8cf9 | 2022-01-12 13:35:12 +0100 | [diff] [blame] | 10 | |
| 11 | #include <no2usb/usb.h> |
| 12 | #include <no2usb/usb_proto.h> |
| 13 | |
| 14 | #include "console.h" |
| 15 | #include "misc.h" |
| 16 | |
| 17 | #include "ice1usb_proto.h" |
| 18 | |
| 19 | |
Sylvain Munaut | 2c33f6d | 2022-01-12 14:12:31 +0100 | [diff] [blame] | 20 | const char *fw_build_str = BUILD_INFO; |
| 21 | |
| 22 | |
Sylvain Munaut | caf8cf9 | 2022-01-12 13:35:12 +0100 | [diff] [blame] | 23 | static enum usb_fnd_resp |
| 24 | _usb_dev_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer) |
| 25 | { |
| 26 | /* Check it's a device-wide vendor request */ |
| 27 | if (USB_REQ_TYPE_RCPT(req) != (USB_REQ_TYPE_VENDOR | USB_REQ_RCPT_DEV)) |
| 28 | return USB_FND_CONTINUE; |
| 29 | |
| 30 | /* Dispatch / Handle */ |
| 31 | switch (req->bRequest) { |
| 32 | case ICE1USB_DEV_GET_CAPABILITIES: |
| 33 | xfer->data[0] = (1 << ICE1USB_DEV_CAP_GPSDO); |
| 34 | xfer->len = 1; |
| 35 | break; |
Sylvain Munaut | 2c33f6d | 2022-01-12 14:12:31 +0100 | [diff] [blame] | 36 | case ICE1USB_DEV_GET_FW_BUILD: |
| 37 | xfer->data = (void*) fw_build_str; |
| 38 | xfer->len = strlen(fw_build_str); |
| 39 | break; |
Sylvain Munaut | caf8cf9 | 2022-01-12 13:35:12 +0100 | [diff] [blame] | 40 | default: |
| 41 | return USB_FND_ERROR; |
| 42 | } |
| 43 | |
| 44 | return USB_FND_SUCCESS; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | static struct usb_fn_drv _dev_drv = { |
| 49 | .ctrl_req = _usb_dev_ctrl_req, |
| 50 | }; |
| 51 | |
| 52 | void |
| 53 | usb_dev_init(void) |
| 54 | { |
| 55 | usb_register_function_driver(&_dev_drv); |
| 56 | } |