diff --git a/src/v5x_data.c b/src/v5x_data.c index 020f450..ade95b0 100644 --- a/src/v5x_data.c +++ b/src/v5x_data.c @@ -350,7 +350,8 @@ void v5x_interface_free(struct v5x_interface *v5if) { struct v5x_user_port *v5x_user_port_create(struct v5x_interface *v5if, uint16_t nr, enum v5x_user_type type, uint8_t ts1, uint8_t ts2) { - struct v5x_user_port *v5up; + struct v5x_user_port *v5up, *tmp; + struct llist_head *add; int i; int rc; @@ -388,7 +389,16 @@ struct v5x_user_port *v5x_user_port_create(struct v5x_interface *v5if, uint16_t if (!v5up) return NULL; - llist_add_tail(&v5up->list, &v5if->user_ports); + /* Insert in a sorted way: all port numbers in ascending order, but all ISDN ports behind PSTN ports */ + add = &v5if->user_ports; + llist_for_each_entry(tmp, &v5if->user_ports, list) { + if (tmp->type == V5X_USER_TYPE_ISDN && type == V5X_USER_TYPE_PSTN) + break; + if (tmp->nr > nr && tmp->type == type) + break; + add = &tmp->list; + } + llist_add(&v5up->list, add); v5up->interface = v5if; v5up->nr = nr;