e1_input: rework configuration of virtual E1 line operations

struct e1inp_line_ops {
-       enum e1inp_line_role    role;
-       char                    *addr;
-       void                    *data;
+       union {
+               struct {
+                       enum e1inp_line_role role;      /* BSC or BTS mode. */
+                       const char *addr;               /* IP address .*/
+                       void *dev;                      /* device parameters. */
+               } ipa;
+               struct {
+                       const char *port;       /* e.g. /dev/ttyUSB0 */
+                       unsigned int delay;
+               } rs232;
+       } cfg;

Now this structure contains the configuration details for the
virtual E1 line, instead of using a pointer.

This also get the line_update callback to its original layout:

+       int (*line_update)(struct e1inp_line *line);
This commit is contained in:
Pablo Neira Ayuso 2011-08-19 18:43:38 +02:00
parent 7e0d006e3c
commit 4e862cbf4b
11 changed files with 63 additions and 45 deletions

View File

@ -126,15 +126,23 @@ struct e1inp_driver {
struct llist_head list;
const char *name;
int (*want_write)(struct e1inp_ts *ts);
int (*line_update)(struct e1inp_line *line, enum e1inp_line_role role, const char *addr);
int (*line_update)(struct e1inp_line *line);
void (*close)(struct e1inp_sign_link *link);
int default_delay;
};
struct e1inp_line_ops {
enum e1inp_line_role role;
char *addr;
void *data;
union {
struct {
enum e1inp_line_role role; /* BSC or BTS mode. */
const char *addr; /* IP address .*/
void *dev; /* device parameters. */
} ipa;
struct {
const char *port; /* e.g. /dev/ttyUSB0 */
unsigned int delay;
} rs232;
} cfg;
struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
void (*sign_link_down)(struct e1inp_line *line);

View File

@ -610,8 +610,7 @@ int e1inp_line_update(struct e1inp_line *line)
return 0;
if (line->driver && line->ops && line->driver->line_update) {
rc = line->driver->line_update(line, line->ops->role,
line->ops->addr);
rc = line->driver->line_update(line);
} else
rc = 0;

View File

@ -385,8 +385,7 @@ static int dahdi_fd_cb(struct osmo_fd *bfd, unsigned int what)
return rc;
}
static int dahdi_e1_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr);
static int dahdi_e1_line_update(struct e1inp_line *line);
struct e1inp_driver dahdi_driver = {
.name = "dahdi",
@ -501,8 +500,7 @@ static int dahdi_e1_setup(struct e1inp_line *line)
return 0;
}
static int dahdi_e1_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr)
static int dahdi_e1_line_update(struct e1inp_line *line)
{
if (line->driver != &dahdi_driver)
return -EINVAL;

View File

@ -318,8 +318,7 @@ static void hsl_close(struct e1inp_sign_link *sign_link)
}
}
static int hsl_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr);
static int hsl_line_update(struct e1inp_line *line);
struct e1inp_driver hsl_driver = {
.name = "hsl",
@ -421,7 +420,7 @@ static int hsl_bts_connect(struct ipa_client_link *link)
struct msgb *msg;
uint8_t *serno;
char serno_buf[16];
struct hsl_unit *unit = link->line->ops->data;
struct hsl_unit *unit = link->line->ops->cfg.ipa.dev;
struct e1inp_sign_link *sign_link;
/* send the minimal message to identify this BTS. */
@ -457,17 +456,17 @@ static int hsl_bts_connect(struct ipa_client_link *link)
return 0;
}
static int hsl_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr)
static int hsl_line_update(struct e1inp_line *line)
{
int ret = -ENOENT;
switch(role) {
switch(line->ops->cfg.ipa.role) {
case E1INP_LINE_R_BSC:
LOGP(DLINP, LOGL_NOTICE, "enabling hsl BSC mode\n");
ret = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
addr, HSL_TCP_PORT, OSMO_SOCK_F_BIND);
line->ops->cfg.ipa.addr,
HSL_TCP_PORT, OSMO_SOCK_F_BIND);
if (ret < 0)
return ret;
@ -489,7 +488,8 @@ static int hsl_line_update(struct e1inp_line *line,
link = ipa_client_link_create(tall_hsl_ctx,
&line->ts[E1INP_SIGN_OML-1],
"hsl", E1INP_SIGN_OML,
addr, HSL_TCP_PORT,
line->ops->cfg.ipa.addr,
HSL_TCP_PORT,
hsl_bts_connect,
hsl_bts_process,
hsl_bts_write,

View File

@ -551,8 +551,7 @@ int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what)
return rc;
}
static int ipaccess_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr);
static int ipaccess_line_update(struct e1inp_line *line);
struct e1inp_driver ipaccess_driver = {
.name = "ipa",
@ -778,7 +777,7 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
link->ofd->fd = -1;
return -EINVAL;
}
rmsg = ipa_bts_id_resp(link->line->ops->data,
rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev,
data + 1, len - 1);
ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len);
msgb_free(rmsg);
@ -814,12 +813,11 @@ static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg)
return 0;
}
static int ipaccess_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr)
static int ipaccess_line_update(struct e1inp_line *line)
{
int ret = -ENOENT;
switch(role) {
switch(line->ops->cfg.ipa.role) {
case E1INP_LINE_R_BSC: {
struct ipa_server_link *oml_link, *rsl_link;
@ -864,7 +862,8 @@ static int ipaccess_line_update(struct e1inp_line *line,
link = ipa_client_link_create(tall_ipa_ctx,
&line->ts[E1INP_SIGN_OML-1],
"ipa", E1INP_SIGN_OML,
addr, IPA_TCP_PORT_OML,
line->ops->cfg.ipa.addr,
IPA_TCP_PORT_OML,
NULL,
ipaccess_bts_cb,
ipaccess_bts_write_cb,
@ -884,7 +883,8 @@ static int ipaccess_line_update(struct e1inp_line *line,
rsl_link = ipa_client_link_create(tall_ipa_ctx,
&line->ts[E1INP_SIGN_RSL-1],
"ipa", E1INP_SIGN_RSL,
addr, IPA_TCP_PORT_RSL,
line->ops->cfg.ipa.addr,
IPA_TCP_PORT_RSL,
NULL,
ipaccess_bts_cb,
ipaccess_bts_write_cb,

View File

@ -380,8 +380,7 @@ static int activate_bchan(struct e1inp_line *line, int ts, int act)
return ret;
}
static int mi_e1_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr);
static int mi_e1_line_update(struct e1inp_line *line);
struct e1inp_driver misdn_driver = {
.name = "misdn",
@ -479,8 +478,7 @@ static int mi_e1_setup(struct e1inp_line *line, int release_l2)
return 0;
}
static int mi_e1_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr)
static int mi_e1_line_update(struct e1inp_line *line)
{
struct mISDN_devinfo devinfo;
int sk, ret, cnt;

View File

@ -277,8 +277,7 @@ rs232_setup(struct e1inp_line *line, const char *serial_port, unsigned int delay
return 0;
}
static int rs232_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr);
static int rs232_line_update(struct e1inp_line *line);
static struct e1inp_driver rs232_driver = {
.name = "rs232",
@ -286,13 +285,13 @@ static struct e1inp_driver rs232_driver = {
.line_update = rs232_line_update,
};
static int rs232_line_update(struct e1inp_line *line,
enum e1inp_line_role role, const char *addr)
static int rs232_line_update(struct e1inp_line *line)
{
if (line->driver != &rs232_driver)
return -EINVAL;
return rs232_setup(line, addr, 0);
return rs232_setup(line, line->ops->cfg.rs232.port,
line->ops->cfg.rs232.delay);
}
int e1inp_rs232_init(void)

View File

@ -190,8 +190,12 @@ int main(void)
osmo_init_logging(&bsc_test_log_info);
struct e1inp_line_ops ops = {
.addr = "0.0.0.0",
.role = E1INP_LINE_R_BSC,
.cfg = {
.ipa = {
.addr = "0.0.0.0",
.role = E1INP_LINE_R_BSC,
},
},
.sign_link_up = sign_link_up,
.sign_link_down = sign_link_down,
.sign_link = sign_link,

View File

@ -231,9 +231,13 @@ int main(void)
osmo_init_logging(&bts_test_log_info);
struct e1inp_line_ops ops = {
.role = E1INP_LINE_R_BTS,
.addr = "127.0.0.1",
.data = &bts_dev_info,
.cfg = {
.ipa = {
.role = E1INP_LINE_R_BTS,
.addr = "127.0.0.1",
.dev = &bts_dev_info,
},
},
.sign_link_up = sign_link_up,
.sign_link_down = sign_link_down,
.sign_link = sign_link,

View File

@ -205,8 +205,12 @@ int main(void)
osmo_init_logging(&bsc_test_log_info);
struct e1inp_line_ops ops = {
.addr = "0.0.0.0",
.role = E1INP_LINE_R_BSC,
.cfg = {
.ipa = {
.addr = "0.0.0.0",
.role = E1INP_LINE_R_BSC,
},
},
.sign_link_up = sign_link_up,
.sign_link_down = sign_link_down,
.sign_link = sign_link,

View File

@ -252,9 +252,13 @@ int main(void)
osmo_init_logging(&bts_test_log_info);
struct e1inp_line_ops ops = {
.role = E1INP_LINE_R_BTS,
.addr = "127.0.0.1",
.data = &bts_dev_info,
.cfg = {
.ipa = {
.role = E1INP_LINE_R_BTS,
.addr = "127.0.0.1",
.dev = &bts_dev_info,
},
},
.sign_link_up = sign_link_up,
.sign_link_down = sign_link_down,
.sign_link = sign_link,