diff options
author | Harald Welte <laforge@osmocom.org> | 2020-06-21 09:16:16 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2020-06-29 17:19:13 +0200 |
commit | 7f0847070694459e88607b41eed54ec10a96424c (patch) | |
tree | 6c8a4a7c88c4c186e05cdfe6ce4ddde3022ed65c /src/usb.c | |
parent | 6b6103778870cba7924ccb01673949bc86d3c9b5 (diff) |
remove code not specific to USB from usb.c to intf_line.c
Change-Id: I7d4d4ab39cb3e7e6a7eb8e738a367122eb3fbee2
Diffstat (limited to 'src/usb.c')
-rw-r--r-- | src/usb.c | 203 |
1 files changed, 6 insertions, 197 deletions
@@ -105,111 +105,9 @@ struct e1_usb_flow { // --------------------------------------------------------------------------- static int -_e1_rx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len) -{ - int rv, cl, oi; - - oi = 0; - - while (oi < len) { - rv = osmo_isdnhdlc_decode(&ts->hdlc_rx, - &buf[oi], len-oi, &cl, - ts->rx_buf, sizeof(ts->rx_buf) - ); - - if (rv > 0) { - printf("RX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->rx_buf, rv)); - write(ts->fd, ts->rx_buf, rv); - } else if (rv < 0 && ts->id == 4) { - printf("ERR RX: %d %d %d [ %s]\n",rv,oi,cl, osmo_hexdump(buf, len)); - } - - oi += cl; - } - - return 0; -} - -static int -_e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len) -{ - int rv, oo, cl; - - oo = 0; - - while (oo < len) { - /* Pending message ? */ - if (!ts->tx_len) { - rv = read(ts->fd, ts->tx_buf, sizeof(ts->tx_buf)); - if (rv > 0) { - printf("TX Message: %d %d [ %s]\n", ts->id, rv, osmo_hexdump(ts->tx_buf, rv)); - ts->tx_len = rv; - ts->tx_ofs = 0; - } - } - - /* */ - rv = osmo_isdnhdlc_encode(&ts->hdlc_tx, - &ts->tx_buf[ts->tx_ofs], ts->tx_len - ts->tx_ofs, &cl, - &buf[oo], len - oo - ); - - if (rv < 0) - printf("ERR TX: %d\n", rv); - - if (ts->tx_ofs < ts->tx_len) - printf("TX chunk %d/%d %d [ %s]\n", ts->tx_ofs, ts->tx_len, cl, osmo_hexdump(&buf[ts->tx_ofs], rv)); - - if (rv > 0) - oo += rv; - - ts->tx_ofs += cl; - if (ts->tx_ofs >= ts->tx_len) { - ts->tx_len = 0; - ts->tx_ofs = 0; - } - } - - return len; -} - -static int e1_usb_xfer_in(struct e1_usb_flow *flow, uint8_t *buf, int size) { - struct e1_line *line = flow->line; - int ftr; - - if (size <= 0) { - printf("IN ERROR: %d\n", size); - return -1; - } - - ftr = (size - 4) / 32; - - for (int tsn=1; tsn<32; tsn++) - { - struct e1_ts *ts = &line->ts[tsn]; - uint8_t buf_ts[32]; - - if (ts->mode == E1_TS_MODE_OFF) - continue; - - for (int i=0; i<ftr; i++) - buf_ts[i] = buf[4+tsn+(i*32)]; - - switch (ts->mode) { - case E1_TS_MODE_RAW: - write(ts->fd, buf_ts, ftr); - break; - case E1_TS_MODE_HDLCFCS: - _e1_rx_hdlcfs(ts, buf_ts, ftr); - break; - default: - continue; - } - } - - return 0; + return e1_line_demux_in(flow->line, buf + 4, size - 4); } static int @@ -217,7 +115,7 @@ e1_usb_xfer_out(struct e1_usb_flow *flow, uint8_t *buf, int size) { struct e1_line *line = flow->line; struct e1_usb_line_data *ld = (struct e1_usb_line_data *) line->drv_data; - int fts, tsz; + int fts; if (size <= 0) { printf("OUT ERROR: %d\n", size); @@ -235,42 +133,9 @@ e1_usb_xfer_out(struct e1_usb_flow *flow, uint8_t *buf, int size) if (ld->r_acc & 0x80000000) ld->r_acc = 0; - /* Prepare */ - tsz = 4 + 32 * fts; - memset(buf, 0xff, tsz); - - /* Header */ - /* FIXME */ + memset(buf, 0xff, 4); - /* Scan timeslots */ - for (int tsn=1; tsn<32; tsn++) - { - struct e1_ts *ts = &line->ts[tsn]; - uint8_t buf_ts[32]; - int l; - - if (ts->mode == E1_TS_MODE_OFF) - continue; - - switch (ts->mode) { - case E1_TS_MODE_RAW: - l = read(ts->fd, buf_ts, fts); - break; - case E1_TS_MODE_HDLCFCS: - l = _e1_tx_hdlcfs(ts, buf_ts, fts); - break; - default: - continue; - } - - if (l <= 0) - continue; - - for (int i=0; i<l; i++) - buf[4+tsn+(i*32)] = buf_ts[i]; - } - - return tsz; + return e1_line_mux_out(line, buf+4, fts); } static int @@ -410,62 +275,6 @@ e1uf_start(struct e1_usb_flow *flow) // --------------------------------------------------------------------------- -// e1d structures -// --------------------------------------------------------------------------- - -struct e1_intf * -_e1_intf_new(struct e1_daemon *e1d, void *drv_data) -{ - struct e1_intf *intf; - - intf = talloc_zero(e1d->ctx, struct e1_intf); - OSMO_ASSERT(intf); - - intf->e1d = e1d; - intf->drv_data = drv_data; - - INIT_LLIST_HEAD(&intf->list); - INIT_LLIST_HEAD(&intf->lines); - - if (!llist_empty(&e1d->interfaces)) { - struct e1_intf *f = llist_first_entry(&e1d->interfaces, struct e1_intf, list); - intf->id = f->id + 1; - } - - llist_add(&intf->list, &e1d->interfaces); - - return intf; -} - -struct e1_line * -_e1_line_new(struct e1_intf *intf, void *drv_data) -{ - struct e1_line *line; - - line = talloc_zero(intf->e1d->ctx, struct e1_line); - OSMO_ASSERT(line); - - line->intf = intf; - line->drv_data = drv_data; - - for (int i=0; i<32; i++) - line->ts[i].id = i; - - INIT_LLIST_HEAD(&line->list); - - if (!llist_empty(&intf->lines)) { - struct e1_line *l = llist_first_entry(&intf->lines, struct e1_line, list); - line->id = l->id + 1; - } - - llist_add(&line->list, &intf->lines); - - return line; -} - - - -// --------------------------------------------------------------------------- // Init / Probing // --------------------------------------------------------------------------- @@ -490,7 +299,7 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev) intf_data = talloc_zero(e1d->ctx, struct e1_usb_intf_data); intf_data->devh = devh; - intf = _e1_intf_new(e1d, intf_data); + intf = e1_intf_new(e1d, intf_data); ret = libusb_get_active_config_descriptor(dev, &cd); if (ret) { @@ -551,7 +360,7 @@ _e1_usb_open_device(struct e1_daemon *e1d, struct libusb_device *dev) return -EINVAL; } - line = _e1_line_new(intf, line_data); + line = e1_line_new(intf, line_data); line_data->flow_in = e1uf_create(line, e1_usb_xfer_in, line_data->ep_in, 2, line_data->pkt_size, 4); line_data->flow_out = e1uf_create(line, e1_usb_xfer_out, line_data->ep_out, 2, line_data->pkt_size, 4); |