static ssize_t store_detach(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { __u32 port = 0, pdev_nr = 0, rhport = 0; struct usb_hcd *hcd; int ret; if (kstrtoint(buf, 10, &port) < 0) return -EINVAL; pdev_nr = port_to_pdev_nr(port); rhport = port_to_rhport(port); if (!valid_port(pdev_nr, rhport)) return -EINVAL; hcd = platform_get_drvdata(*(vhci_pdevs + pdev_nr)); if (hcd == NULL) { dev_err(dev, "port is not ready %u\n", port); return -EAGAIN; } ret = vhci_port_disconnect(hcd_to_vhci(hcd), rhport); if (ret < 0) return -EINVAL; usbip_dbg_vhci_sysfs("Leave\n"); return count; }
void get_addr_port(char ** addr, char ** port) { char * value; value = getenv("OBSERVER_ADDR"); if (value != NULL && !valid_addr(value)) * addr = value; value = getenv("OBSERVER_PORT"); if (value != NULL && !valid_port(value)) * port = value; }
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) { if (!valid_port(port)) return -EINVAL; if (!gpio_is_valid(pdata->vbus_pin[port])) return -EINVAL; return gpio_get_value(pdata->vbus_pin[port]) ^ pdata->vbus_pin_active_low[port]; }
static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) { if (!valid_port(port)) return; if (!gpio_is_valid(pdata->vbus_pin[port])) return; gpio_set_value(pdata->vbus_pin[port], pdata->vbus_pin_active_low[port] ^ enable); }
static int valid_args(__u32 pdev_nr, __u32 rhport, enum usb_device_speed speed) { if (!valid_port(pdev_nr, rhport)) { return 0; } switch (speed) { case USB_SPEED_LOW: case USB_SPEED_FULL: case USB_SPEED_HIGH: case USB_SPEED_WIRELESS: break; default: pr_err("Failed attach request for unsupported USB speed: %s\n", usb_speed_string(speed)); return 0; } return 1; }
static ssize_t store_detach(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { __u32 port = 0, pdev_nr = 0, rhport = 0; struct usb_hcd *hcd; struct vhci_hcd *vhci_hcd; int ret; if (kstrtoint(buf, 10, &port) < 0) return -EINVAL; pdev_nr = port_to_pdev_nr(port); rhport = port_to_rhport(port); if (!valid_port(pdev_nr, rhport)) return -EINVAL; hcd = platform_get_drvdata(vhcis[pdev_nr].pdev); if (hcd == NULL) { dev_err(dev, "port is not ready %u\n", port); return -EAGAIN; } usbip_dbg_vhci_sysfs("rhport %d\n", rhport); if ((port / VHCI_HC_PORTS) % 2) vhci_hcd = hcd_to_vhci_hcd(hcd)->vhci->vhci_hcd_ss; else vhci_hcd = hcd_to_vhci_hcd(hcd)->vhci->vhci_hcd_hs; ret = vhci_port_disconnect(vhci_hcd, rhport); if (ret < 0) return -EINVAL; usbip_dbg_vhci_sysfs("Leave\n"); return count; }
/* * Look at the control requests to the root hub and see if we need to override. */ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) { struct at91_usbh_data *pdata = hcd->self.controller->platform_data; struct usb_hub_descriptor *desc; int ret = -EINVAL; u32 *data = (u32 *)buf; dev_dbg(hcd->self.controller, "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", hcd, typeReq, wValue, wIndex, buf, wLength); wIndex--; switch (typeReq) { case SetPortFeature: if (wValue == USB_PORT_FEAT_POWER) { dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); if (valid_port(wIndex)) { ohci_at91_usb_set_power(pdata, wIndex, 1); ret = 0; } goto out; } break; case ClearPortFeature: switch (wValue) { case USB_PORT_FEAT_C_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: C_OVER_CURRENT\n"); if (valid_port(wIndex)) { pdata->overcurrent_changed[wIndex] = 0; pdata->overcurrent_status[wIndex] = 0; } goto out; case USB_PORT_FEAT_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: OVER_CURRENT\n"); if (valid_port(wIndex)) pdata->overcurrent_status[wIndex] = 0; goto out; case USB_PORT_FEAT_POWER: dev_dbg(hcd->self.controller, "ClearPortFeature: POWER\n"); if (valid_port(wIndex)) { ohci_at91_usb_set_power(pdata, wIndex, 0); return 0; } } break; } ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); if (ret) goto out; switch (typeReq) { case GetHubDescriptor: /* update the hub's descriptor */ desc = (struct usb_hub_descriptor *)buf; dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", desc->wHubCharacteristics); /* remove the old configurations for power-switching, and * over-current protection, and insert our new configuration */ desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); desc->wHubCharacteristics |= cpu_to_le16(0x0001); if (pdata->overcurrent_supported) { desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001); } dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", desc->wHubCharacteristics); return ret; case GetPortStatus: /* check port status */ dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); if (valid_port(wIndex)) { if (!ohci_at91_usb_get_power(pdata, wIndex)) *data &= ~cpu_to_le32(RH_PS_PPS); if (pdata->overcurrent_changed[wIndex]) *data |= cpu_to_le32(RH_PS_OCIC); if (pdata->overcurrent_status[wIndex]) *data |= cpu_to_le32(RH_PS_POCI); } } out: return ret; }
static int ohci_s3c2410_hub_control ( struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) { struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); struct usb_hub_descriptor *desc; int ret = -EINVAL; u32 *data = (u32 *)buf; dev_dbg(hcd->self.controller, "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", hcd, typeReq, wValue, wIndex, buf, wLength); /* if we are only an humble host without any special capabilities * process the request straight away and exit */ if (info == NULL) { ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); goto out; } /* check the request to see if it needs handling */ switch (typeReq) { case SetPortFeature: if (wValue == USB_PORT_FEAT_POWER) { dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); s3c2410_usb_set_power(info, wIndex, 1); goto out; } break; case ClearPortFeature: switch (wValue) { case USB_PORT_FEAT_C_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: C_OVER_CURRENT\n"); if (valid_port(wIndex)) { info->port[wIndex-1].oc_changed = 0; info->port[wIndex-1].oc_status = 0; } goto out; case USB_PORT_FEAT_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: OVER_CURRENT\n"); if (valid_port(wIndex)) { info->port[wIndex-1].oc_status = 0; } goto out; case USB_PORT_FEAT_POWER: dev_dbg(hcd->self.controller, "ClearPortFeature: POWER\n"); if (valid_port(wIndex)) { s3c2410_usb_set_power(info, wIndex, 0); return 0; } } break; } ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); if (ret) goto out; switch (typeReq) { case GetHubDescriptor: /* update the hub's descriptor */ desc = (struct usb_hub_descriptor *)buf; if (info->power_control == NULL) return ret; dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", desc->wHubCharacteristics); /* remove the old configurations for power-switching, and * over-current protection, and insert our new configuration */ desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); desc->wHubCharacteristics |= cpu_to_le16(0x0001); if (info->enable_oc) { desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001); } dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", desc->wHubCharacteristics); return ret; case GetPortStatus: /* check port status */ dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); if (valid_port(wIndex)) { if (info->port[wIndex-1].oc_changed) { *data |= cpu_to_le32(RH_PS_OCIC); } if (info->port[wIndex-1].oc_status) { *data |= cpu_to_le32(RH_PS_POCI); } } } out: return ret; }
static int ohci_s3c2410_hub_control( struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) { struct s3c2410_hcd_info *info = to_s3c2410_info(hcd); struct usb_hub_descriptor *desc; int ret = -EINVAL; u32 *data = (u32 *)buf; dev_dbg(hcd->self.controller, "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", hcd, typeReq, wValue, wIndex, buf, wLength); /* */ if (info == NULL) { ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); goto out; } /* */ switch (typeReq) { case SetPortFeature: if (wValue == USB_PORT_FEAT_POWER) { dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); s3c2410_usb_set_power(info, wIndex, 1); goto out; } break; case ClearPortFeature: switch (wValue) { case USB_PORT_FEAT_C_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: C_OVER_CURRENT\n"); if (valid_port(wIndex)) { info->port[wIndex-1].oc_changed = 0; info->port[wIndex-1].oc_status = 0; } goto out; case USB_PORT_FEAT_OVER_CURRENT: dev_dbg(hcd->self.controller, "ClearPortFeature: OVER_CURRENT\n"); if (valid_port(wIndex)) info->port[wIndex-1].oc_status = 0; goto out; case USB_PORT_FEAT_POWER: dev_dbg(hcd->self.controller, "ClearPortFeature: POWER\n"); if (valid_port(wIndex)) { s3c2410_usb_set_power(info, wIndex, 0); return 0; } } break; } ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); if (ret) goto out; switch (typeReq) { case GetHubDescriptor: /* */ desc = (struct usb_hub_descriptor *)buf; if (info->power_control == NULL) return ret; dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", desc->wHubCharacteristics); /* */ desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); desc->wHubCharacteristics |= cpu_to_le16(0x0001); if (info->enable_oc) { desc->wHubCharacteristics &= ~cpu_to_le16( HUB_CHAR_OCPM); desc->wHubCharacteristics |= cpu_to_le16( 0x0008 | 0x0001); } dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", desc->wHubCharacteristics); return ret; case GetPortStatus: /* */ dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); if (valid_port(wIndex)) { if (info->port[wIndex-1].oc_changed) *data |= cpu_to_le32(RH_PS_OCIC); if (info->port[wIndex-1].oc_status) *data |= cpu_to_le32(RH_PS_POCI); } } out: return ret; }
int main(int argc, char *argv[]) { int port = DEFAULTPORT; /* Handle command line options. */ int next_opt = 0; const char *short_opts = "hp:"; const struct option long_opts[] = { { "help", 0, NULL, 'h' }, { "port", 1, NULL, 'p' }, { NULL, 0, NULL, 0 } }; while (next_opt != -1) { next_opt = getopt_long(argc, argv, short_opts, long_opts, NULL); switch (next_opt) { case 'h': usage(stdout, 0); break; case 'p': if ((port = valid_port(optarg)) < 0) { fprintf(stderr, "Port must range from %d - %d\n\n", MINPORT, MAXPORT); usage(stderr, 1); } break; case '?': usage(stderr, 1); break; case -1: break; default: fprintf(stderr, "Fatal error, aborting...\n"); exit(1); } } /* There shouldn't be any other parameters. */ if (argv[optind]) { fprintf(stderr, "Invalid parameter `%s'\n\n", argv[optind]); usage(stderr, 1); } /* Install the signal handlers to cleanup after children and at exit. */ signal(SIGCHLD, (void (*)())cleanup); signal(SIGINT, (void(*)())wrapup); /* Create and configure the ssh session. */ session=ssh_new(); sshbind=ssh_bind_new(); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, LISTENADDRESS); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "ssh-rsa"); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,RSA_KEYFILE); /* Listen on `port' for connections. */ if (ssh_bind_listen(sshbind) < 0) { printf("Error listening to socket: %s\n",ssh_get_error(sshbind)); return -1; } if (DEBUG) { printf("Listening on port %d.\n", port); } /* Loop forever, waiting for and handling connection attempts. */ while (1) { if (ssh_bind_accept(sshbind, session) == SSH_ERROR) { fprintf(stderr, "Error accepting a connection: `%s'.\n",ssh_get_error(sshbind)); return -1; } if (DEBUG) { printf("Accepted a connection.\n"); } switch (fork()) { case -1: fprintf(stderr,"Fork returned error: `%d'.\n",-1); exit(-1); case 0: exit(handle_auth(session)); default: break; } } return 0; }