laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/27015 )
Change subject: e1_{intf,line}_new: Allow caller to specify the numeric identifier ......................................................................
e1_{intf,line}_new: Allow caller to specify the numeric identifier
This will be used by the upcoming VTY interface changes.
Change-Id: I9ff80831a3e3e3cb6dae178f8b438a9f3f4747df --- M src/e1d.h M src/intf_line.c M src/usb.c M src/vpair.c 4 files changed, 43 insertions(+), 16 deletions(-)
Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/e1d.h b/src/e1d.h index a0c8ceb..b76df7a 100644 --- a/src/e1d.h +++ b/src/e1d.h @@ -166,7 +166,7 @@ e1_intf_find_line(struct e1_intf *intf, uint8_t id);
struct e1_intf * -e1_intf_new(struct e1_daemon *e1d, void *drv_data); +e1_intf_new(struct e1_daemon *e1d, int intf_id, void *drv_data);
struct e1_intf * e1d_find_intf(struct e1_daemon *e1d, uint8_t id); @@ -179,7 +179,7 @@ e1_intf_find_line(struct e1_intf *intf, uint8_t id);
struct e1_line * -e1_line_new(struct e1_intf *intf, void *drv_data); +e1_line_new(struct e1_intf *intf, int line_id, void *drv_data);
void e1_line_destroy(struct e1_line *line); diff --git a/src/intf_line.c b/src/intf_line.c index 1f833fb..cb3f277 100644 --- a/src/intf_line.c +++ b/src/intf_line.c @@ -107,11 +107,21 @@ return NULL; }
+/* intf_id can be specified as '-1' to mean "auto-allocate intf->id" */ struct e1_intf * -e1_intf_new(struct e1_daemon *e1d, void *drv_data) +e1_intf_new(struct e1_daemon *e1d, int intf_id, void *drv_data) { struct e1_intf *intf;
+ if (intf_id != -1) { + /* ensure non-duplicate interface number */ + intf = e1d_find_intf(e1d, intf_id); + if (intf) { + LOGPIF(intf, DE1D, LOGL_ERROR, "Cannot create duplicate interface %d\n", intf_id); + return NULL; + } + } + intf = talloc_zero(e1d->ctx, struct e1_intf); OSMO_ASSERT(intf);
@@ -121,10 +131,14 @@ INIT_LLIST_HEAD(&intf->list); INIT_LLIST_HEAD(&intf->lines);
- if (!llist_empty(&e1d->interfaces)) { - struct e1_intf *f = llist_last_entry(&e1d->interfaces, struct e1_intf, list); - intf->id = f->id + 1; - } + if (intf_id == -1) { + if (!llist_empty(&e1d->interfaces)) { + struct e1_intf *f = llist_last_entry(&e1d->interfaces, struct e1_intf, list); + intf->id = f->id + 1; + } else + intf->id = 0; + } else + intf->id = intf_id;
llist_add_tail(&intf->list, &e1d->interfaces);
@@ -180,11 +194,20 @@ ts->fd = -1; }
+/* line_id can be specified as '-1' to mean "auto-allocate intf->id" */ struct e1_line * -e1_line_new(struct e1_intf *intf, void *drv_data) +e1_line_new(struct e1_intf *intf, int line_id, void *drv_data) { struct e1_line *line;
+ if (line_id != -1) { + line = e1_intf_find_line(intf, line_id); + if (line) { + LOGPLI(line, DE1D, LOGL_ERROR, "Cannot create duplicate line %d\n", line_id); + return NULL; + } + } + line = talloc_zero(intf->e1d->ctx, struct e1_line); OSMO_ASSERT(line);
@@ -198,10 +221,14 @@
INIT_LLIST_HEAD(&line->list);
- if (!llist_empty(&intf->lines)) { - struct e1_line *l = llist_last_entry(&intf->lines, struct e1_line, list); - line->id = l->id + 1; - } + if (line_id == -1) { + if (!llist_empty(&intf->lines)) { + struct e1_line *l = llist_last_entry(&intf->lines, struct e1_line, list); + line->id = l->id + 1; + } else + line->id = 0; + } else + line->id = line_id;
line->ctrs = rate_ctr_group_alloc(line, &line_ctrg_desc, line->id); OSMO_ASSERT(line->ctrs); diff --git a/src/usb.c b/src/usb.c index 0c0afe4..0100c31 100644 --- a/src/usb.c +++ b/src/usb.c @@ -543,7 +543,7 @@ 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, -1, intf_data); intf->drv = E1_DRIVER_USB;
ret = libusb_get_active_config_descriptor(dev, &cd); @@ -608,7 +608,7 @@ return -EINVAL; }
- line = e1_line_new(intf, line_data); + line = e1_line_new(intf, -1, line_data);
line_data->flow_in = e1uf_create(line, e1_usb_xfer_in, line_data->ep_in, 4, line_data->pkt_size, 4); line_data->flow_out = e1uf_create(line, e1_usb_xfer_out, line_data->ep_out, 4, line_data->pkt_size, 4); diff --git a/src/vpair.c b/src/vpair.c index 8484be0..524f998 100644 --- a/src/vpair.c +++ b/src/vpair.c @@ -67,14 +67,14 @@
intf_data = talloc_zero(e1d->ctx, struct ve1_intf_data);
- intf = e1_intf_new(e1d, intf_data); + intf = e1_intf_new(e1d, -1, intf_data); intf->drv = E1_DRIVER_VPAIR;
for (i = 0; i < num_lines; i++) { struct ve1_line_data *line_data;
line_data = talloc_zero(e1d->ctx, struct ve1_line_data); - e1_line_new(intf, line_data); + e1_line_new(intf, -1, line_data); }
return intf;