Lines Matching refs:uds_ctx

33 static int nonstd_request(struct usbd_context *const uds_ctx,
46 static void ch9_set_ctrl_type(struct usbd_context *const uds_ctx, in ch9_set_ctrl_type() argument
49 uds_ctx->ch9_data.ctrl_type = type; in ch9_set_ctrl_type()
52 static int ch9_get_ctrl_type(struct usbd_context *const uds_ctx) in ch9_get_ctrl_type() argument
54 return uds_ctx->ch9_data.ctrl_type; in ch9_get_ctrl_type()
57 static int post_status_stage(struct usbd_context *const uds_ctx) in post_status_stage() argument
59 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in post_status_stage()
63 ret = udc_set_address(uds_ctx->dev, setup->wValue); in post_status_stage()
73 ret = udc_test_mode(uds_ctx->dev, mode, false); in post_status_stage()
79 uds_ctx->ch9_data.post_status = false; in post_status_stage()
84 static int sreq_set_address(struct usbd_context *const uds_ctx) in sreq_set_address() argument
86 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_set_address()
87 struct udc_device_caps caps = udc_caps(uds_ctx->dev); in sreq_set_address()
100 if (usbd_state_is_configured(uds_ctx)) { in sreq_set_address()
108 ret = udc_set_address(uds_ctx->dev, setup->wValue); in sreq_set_address()
114 uds_ctx->ch9_data.post_status = true; in sreq_set_address()
117 if (usbd_state_is_address(uds_ctx) && setup->wValue == 0) { in sreq_set_address()
118 uds_ctx->ch9_data.state = USBD_STATE_DEFAULT; in sreq_set_address()
120 uds_ctx->ch9_data.state = USBD_STATE_ADDRESS; in sreq_set_address()
127 static int sreq_set_configuration(struct usbd_context *const uds_ctx) in sreq_set_configuration() argument
129 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_set_configuration()
130 const enum usbd_speed speed = usbd_bus_speed(uds_ctx); in sreq_set_configuration()
146 if (usbd_state_is_default(uds_ctx)) { in sreq_set_configuration()
151 if (setup->wValue && !usbd_config_exist(uds_ctx, speed, setup->wValue)) { in sreq_set_configuration()
156 if (setup->wValue == usbd_get_config_value(uds_ctx)) { in sreq_set_configuration()
161 ret = usbd_config_set(uds_ctx, setup->wValue); in sreq_set_configuration()
170 uds_ctx->ch9_data.state = USBD_STATE_ADDRESS; in sreq_set_configuration()
172 uds_ctx->ch9_data.state = USBD_STATE_CONFIGURED; in sreq_set_configuration()
176 usbd_msg_pub_simple(uds_ctx, USBD_MSG_CONFIGURATION, setup->wValue); in sreq_set_configuration()
182 static int sreq_set_interface(struct usbd_context *const uds_ctx) in sreq_set_interface() argument
184 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_set_interface()
203 if (!usbd_state_is_configured(uds_ctx)) { in sreq_set_interface()
208 ret = usbd_interface_set(uds_ctx, setup->wIndex, setup->wValue); in sreq_set_interface()
218 static void sreq_feature_halt_notify(struct usbd_context *const uds_ctx, in sreq_feature_halt_notify() argument
221 struct usbd_class_node *c_nd = usbd_class_get_by_ep(uds_ctx, ep); in sreq_feature_halt_notify()
228 static int sreq_clear_feature(struct usbd_context *const uds_ctx) in sreq_clear_feature() argument
230 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_clear_feature()
241 if (usbd_state_is_default(uds_ctx)) { in sreq_clear_feature()
246 if (usbd_state_is_address(uds_ctx) && setup->wIndex) { in sreq_clear_feature()
260 uds_ctx->status.rwup = false; in sreq_clear_feature()
266 errno = usbd_ep_clear_halt(uds_ctx, ep); in sreq_clear_feature()
270 sreq_feature_halt_notify(uds_ctx, ep, false); in sreq_clear_feature()
283 static int set_feature_test_mode(struct usbd_context *const uds_ctx) in set_feature_test_mode() argument
285 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in set_feature_test_mode()
294 if (udc_test_mode(uds_ctx->dev, mode, true) != 0) { in set_feature_test_mode()
299 uds_ctx->ch9_data.post_status = true; in set_feature_test_mode()
304 static int sreq_set_feature(struct usbd_context *const uds_ctx) in sreq_set_feature() argument
306 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_set_feature()
317 return set_feature_test_mode(uds_ctx); in sreq_set_feature()
324 if (usbd_state_is_default(uds_ctx)) { in sreq_set_feature()
329 if (usbd_state_is_address(uds_ctx) && setup->wIndex) { in sreq_set_feature()
343 uds_ctx->status.rwup = true; in sreq_set_feature()
349 errno = usbd_ep_set_halt(uds_ctx, ep); in sreq_set_feature()
353 sreq_feature_halt_notify(uds_ctx, ep, true); in sreq_set_feature()
366 static int std_request_to_device(struct usbd_context *const uds_ctx, in std_request_to_device() argument
369 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in std_request_to_device()
374 ret = sreq_set_address(uds_ctx); in std_request_to_device()
377 ret = sreq_set_configuration(uds_ctx); in std_request_to_device()
380 ret = sreq_set_interface(uds_ctx); in std_request_to_device()
383 ret = sreq_clear_feature(uds_ctx); in std_request_to_device()
386 ret = sreq_set_feature(uds_ctx); in std_request_to_device()
397 static int sreq_get_status(struct usbd_context *const uds_ctx, in sreq_get_status() argument
400 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_status()
410 if (usbd_state_is_default(uds_ctx)) { in sreq_get_status()
415 if (usbd_state_is_address(uds_ctx) && setup->wIndex) { in sreq_get_status()
427 response = uds_ctx->status.rwup ? in sreq_get_status()
431 response = usbd_ep_is_halted(uds_ctx, ep) ? BIT(0) : 0; in sreq_get_status()
457 static int sreq_get_desc_cfg(struct usbd_context *const uds_ctx, in sreq_get_desc_cfg() argument
462 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_desc_cfg()
463 enum usbd_speed speed = usbd_bus_speed(uds_ctx); in sreq_get_desc_cfg()
475 if (other_cfg && usbd_caps_speed(uds_ctx) != USBD_SPEED_HS) { in sreq_get_desc_cfg()
490 cfg_nd = usbd_config_get(uds_ctx, get_desc_speed, idx + 1); in sreq_get_desc_cfg()
609 static int sreq_get_desc_dev(struct usbd_context *const uds_ctx, in sreq_get_desc_dev() argument
612 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_desc_dev()
618 switch (usbd_bus_speed(uds_ctx)) { in sreq_get_desc_dev()
620 head = uds_ctx->fs_desc; in sreq_get_desc_dev()
623 head = uds_ctx->hs_desc; in sreq_get_desc_dev()
635 static int sreq_get_desc_str(struct usbd_context *const uds_ctx, in sreq_get_desc_str() argument
638 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_desc_str()
643 d_nd = usbd_get_descriptor(uds_ctx, USB_DESC_STRING, idx); in sreq_get_desc_str()
667 static int sreq_get_dev_qualifier(struct usbd_context *const uds_ctx, in sreq_get_dev_qualifier() argument
670 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_dev_qualifier()
673 usbd_bus_speed(uds_ctx) == USBD_SPEED_FS ? in sreq_get_dev_qualifier()
674 uds_ctx->hs_desc : uds_ctx->fs_desc; in sreq_get_dev_qualifier()
692 if (usbd_caps_speed(uds_ctx) != USBD_SPEED_HS) { in sreq_get_dev_qualifier()
704 static void desc_fill_bos_root(struct usbd_context *const uds_ctx, in desc_fill_bos_root() argument
714 SYS_DLIST_FOR_EACH_CONTAINER(&uds_ctx->descriptors, desc_nd, node) { in desc_fill_bos_root()
722 static int sreq_get_desc_bos(struct usbd_context *const uds_ctx, in sreq_get_desc_bos() argument
725 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_desc_bos()
731 switch (usbd_bus_speed(uds_ctx)) { in sreq_get_desc_bos()
733 dev_dsc = uds_ctx->fs_desc; in sreq_get_desc_bos()
736 dev_dsc = uds_ctx->hs_desc; in sreq_get_desc_bos()
748 desc_fill_bos_root(uds_ctx, &bos); in sreq_get_desc_bos()
761 SYS_DLIST_FOR_EACH_CONTAINER(&uds_ctx->descriptors, desc_nd, node) { in sreq_get_desc_bos()
777 static int sreq_get_descriptor(struct usbd_context *const uds_ctx, in sreq_get_descriptor() argument
780 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_descriptor()
794 return nonstd_request(uds_ctx, buf); in sreq_get_descriptor()
799 return sreq_get_desc_dev(uds_ctx, buf); in sreq_get_descriptor()
801 return sreq_get_desc_cfg(uds_ctx, buf, desc_idx, false); in sreq_get_descriptor()
803 return sreq_get_desc_cfg(uds_ctx, buf, desc_idx, true); in sreq_get_descriptor()
805 return sreq_get_desc_str(uds_ctx, buf, desc_idx); in sreq_get_descriptor()
807 return sreq_get_dev_qualifier(uds_ctx, buf); in sreq_get_descriptor()
809 return sreq_get_desc_bos(uds_ctx, buf); in sreq_get_descriptor()
820 static int sreq_get_configuration(struct usbd_context *const uds_ctx, in sreq_get_configuration() argument
824 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_configuration()
825 uint8_t cfg = usbd_get_config_value(uds_ctx); in sreq_get_configuration()
828 if (usbd_state_is_default(uds_ctx)) { in sreq_get_configuration()
848 static int sreq_get_interface(struct usbd_context *const uds_ctx, in sreq_get_interface() argument
851 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in sreq_get_interface()
862 cfg_nd = usbd_config_get_current(uds_ctx); in sreq_get_interface()
876 if (usbd_get_alt_value(uds_ctx, setup->wIndex, &cur_alt)) { in sreq_get_interface()
899 static int std_request_to_host(struct usbd_context *const uds_ctx, in std_request_to_host() argument
902 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in std_request_to_host()
907 ret = sreq_get_status(uds_ctx, buf); in std_request_to_host()
910 ret = sreq_get_descriptor(uds_ctx, buf); in std_request_to_host()
913 ret = sreq_get_configuration(uds_ctx, buf); in std_request_to_host()
916 ret = sreq_get_interface(uds_ctx, buf); in std_request_to_host()
927 static int vendor_device_request(struct usbd_context *const uds_ctx, in vendor_device_request() argument
930 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in vendor_device_request()
933 vreq_nd = usbd_device_get_vreq(uds_ctx, setup->bRequest); in vendor_device_request()
941 errno = vreq_nd->to_dev(uds_ctx, setup, buf); in vendor_device_request()
947 errno = vreq_nd->to_host(uds_ctx, setup, buf); in vendor_device_request()
955 static int nonstd_request(struct usbd_context *const uds_ctx, in nonstd_request() argument
958 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in nonstd_request()
964 c_nd = usbd_class_get_by_ep(uds_ctx, setup->wIndex); in nonstd_request()
967 c_nd = usbd_class_get_by_iface(uds_ctx, setup->wIndex); in nonstd_request()
970 c_nd = usbd_class_get_by_req(uds_ctx, setup->bRequest); in nonstd_request()
983 return vendor_device_request(uds_ctx, dbuf); in nonstd_request()
989 static int handle_setup_request(struct usbd_context *const uds_ctx, in handle_setup_request() argument
992 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in handle_setup_request()
1000 ret = std_request_to_device(uds_ctx, buf); in handle_setup_request()
1002 ret = std_request_to_host(uds_ctx, buf); in handle_setup_request()
1007 ret = nonstd_request(uds_ctx, buf); in handle_setup_request()
1022 uds_ctx->ch9_data.state); in handle_setup_request()
1029 static int ctrl_xfer_get_setup(struct usbd_context *const uds_ctx, in ctrl_xfer_get_setup() argument
1032 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in ctrl_xfer_get_setup()
1103 int usbd_handle_ctrl_xfer(struct usbd_context *const uds_ctx, in usbd_handle_ctrl_xfer() argument
1106 struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx); in usbd_handle_ctrl_xfer()
1135 if (ctrl_xfer_get_setup(uds_ctx, buf)) { in usbd_handle_ctrl_xfer()
1152 ret = handle_setup_request(uds_ctx, next_buf); in usbd_handle_ctrl_xfer()
1167 ch9_set_ctrl_type(uds_ctx, CTRL_AWAIT_STATUS_STAGE); in usbd_handle_ctrl_xfer()
1176 ret = usbd_ep_ctrl_enqueue(uds_ctx, next_buf); in usbd_handle_ctrl_xfer()
1179 ret = usbd_ep_ctrl_enqueue(uds_ctx, next_buf); in usbd_handle_ctrl_xfer()
1186 if (ch9_get_ctrl_type(uds_ctx) == CTRL_AWAIT_STATUS_STAGE) { in usbd_handle_ctrl_xfer()
1200 if (ch9_get_ctrl_type(uds_ctx) == CTRL_AWAIT_STATUS_STAGE) { in usbd_handle_ctrl_xfer()
1202 if (unlikely(uds_ctx->ch9_data.post_status)) { in usbd_handle_ctrl_xfer()
1203 ret = post_status_stage(uds_ctx); in usbd_handle_ctrl_xfer()
1221 ret = udc_ep_set_halt(uds_ctx->dev, USB_CONTROL_EP_IN); in usbd_handle_ctrl_xfer()
1225 ret = udc_ep_set_halt(uds_ctx->dev, ep); in usbd_handle_ctrl_xfer()
1227 ret = udc_ep_set_halt(uds_ctx->dev, USB_CONTROL_EP_IN); in usbd_handle_ctrl_xfer()
1230 ch9_set_ctrl_type(uds_ctx, CTRL_AWAIT_SETUP_DATA); in usbd_handle_ctrl_xfer()
1235 int usbd_init_control_pipe(struct usbd_context *const uds_ctx) in usbd_init_control_pipe() argument
1237 uds_ctx->ch9_data.state = USBD_STATE_DEFAULT; in usbd_init_control_pipe()
1238 ch9_set_ctrl_type(uds_ctx, CTRL_AWAIT_SETUP_DATA); in usbd_init_control_pipe()