#include #include "v5x_internal.h" #include "v5x_vty.h" #include "../config.h" extern struct v5x_instance *v5i; enum v5_vty_node { INTERFACE_NODE_V51 = _LAST_OSMOVTY_NODE + 1, INTERFACE_NODE_V52, }; static struct cmd_node interface_node_v51 = { INTERFACE_NODE_V51, "%s(config-v5.1-if)# ", 1, }; static struct cmd_node interface_node_v52 = { INTERFACE_NODE_V52, "%s(config-v5.2-if)# ", 1, }; static int v5le_vty_is_config_node(struct vty *vty, int node) { switch (node) { case CONFIG_NODE: return 0; default: return 1; } } static int v5le_vty_go_parent(struct vty *vty) { switch (vty->node) { default: if (v5le_vty_is_config_node(vty, vty->node)) vty->node = CONFIG_NODE; else vty->node = ENABLE_NODE; vty->index = NULL; } return vty->node; } struct vty_app_info vty_info = { .name = "OsmoV5LE", .version = PACKAGE_VERSION, .go_parent_cb = v5le_vty_go_parent, .is_config_node = v5le_vty_is_config_node, }; #warning hacking int ph_data_req(struct msgb *msg, void *cbdata); DEFUN(cfg_interface, cfg_interface_cmd, "interface (v5.1|v5.2)", "Configure V5 interface\n" "Configure as V5.1 interface\n" "Configure as V5.2 interface") { struct v5x_interface *v5if = NULL; enum v5x_dialect dialect = V5X_DIALECT_V51; if (!llist_empty(&v5i->interfaces)) v5if = (struct v5x_interface *)v5i->interfaces.next; if (!strcasecmp(argv[0], "v5.2")) dialect = V5X_DIALECT_V52; if (!v5if) { v5if = v5x_interface_alloc(v5i, dialect, ph_data_req); if (!v5if) { vty_out(vty, "%%Failed to create interface%s", VTY_NEWLINE); return CMD_WARNING; } } else { vty_out(vty, "%%Interface already created. If interface type has been changed, restart this " "application.%s", VTY_NEWLINE); } vty->node = (v5if->dialect == V5X_DIALECT_V51) ? INTERFACE_NODE_V51 : INTERFACE_NODE_V52; vty->index = v5if; return CMD_SUCCESS; } DEFUN(cfg_no_interface, cfg_no_interface_cmd, "no interface", NO_STR "Remove V5 interface") { struct v5x_interface *v5if = NULL; if (!llist_empty(&v5i->interfaces)) v5if = (struct v5x_interface *)v5i->interfaces.next; if (v5if) { v5x_interface_free(v5if); } return CMD_SUCCESS; } DEFUN(cfg_interface_id, cfg_interface_id_cmd, "id <0-16777215>", "Set interface ID\n" "Interface ID") { struct v5x_interface *v5if = vty->index; v5if->id = atoi(argv[0]); return CMD_SUCCESS; } DEFUN(cfg_interface_variant, cfg_interface_variant_cmd, "variant <0-127>", "Set interface provisioning variant\n" "Variant value") { struct v5x_interface *v5if = vty->index; v5if->variant = atoi(argv[0]); return CMD_SUCCESS; } DEFUN(cfg_port_pstn_v51, cfg_port_pstn_cmd_v51, "port pstn <0-32767> <1-31>", "Create V5 user port\n" "PSTN user port\n" "L3 address\n" "Time slot") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), false); if (v5up) { vty_out(vty, "%%Given PSTN user port already exists, remove first.%s", VTY_NEWLINE); return CMD_WARNING; } v5up = v5x_user_port_create(v5if, atoi(argv[0]), V5X_USER_TYPE_PSTN, atoi(argv[1]), 0); if (!v5up) { vty_out(vty, "%%Failed to create PSTN user port.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS; } DEFUN(cfg_port_pstn_v52, cfg_port_pstn_cmd_v52, "port pstn <0-32767>", "Create V5 user port\n" "PSTN user port\n" "L3 address") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), false); if (v5up) { vty_out(vty, "%%Given PSTN user port already exists, remove first.%s", VTY_NEWLINE); return CMD_WARNING; } v5up = v5x_user_port_create(v5if, atoi(argv[0]), V5X_USER_TYPE_PSTN, 0, 0); if (!v5up) { vty_out(vty, "%%Failed to create PSTN user port.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS; } DEFUN(cfg_no_port_pstn, cfg_no_port_pstn_cmd, "no port pstn <0-32767>", NO_STR "Delete V5 user port\n" "PSTN user port\n" "L3 address\n") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), false); if (!v5up) { vty_out(vty, "%%Given PSTN user port does not exist.%s", VTY_NEWLINE); return CMD_WARNING; } v5x_user_port_destroy(v5up); return CMD_SUCCESS; } DEFUN(cfg_port_isdn_v51, cfg_port_isdn_cmd_v51, "port isdn <0-8175> <1-31> <1-31>", "Create V5 user port\n" "ISDN user port\n" "L3 address\n" "Time slot 1\n" "Time slot 2\n") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), true); if (v5up) { vty_out(vty, "%%Given ISDN user port already exists, remove first.%s", VTY_NEWLINE); return CMD_WARNING; } v5up = v5x_user_port_create(v5if, atoi(argv[0]), V5X_USER_TYPE_ISDN, atoi(argv[1]), atoi(argv[2])); if (!v5up) { vty_out(vty, "%%Failed to create ISDN user port.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS; } DEFUN(cfg_port_isdn_v52, cfg_port_isdn_cmd_v52, "port isdn <0-8175>", "Create V5 user port\n" "ISDN user port\n" "L3 address\n") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), true); if (v5up) { vty_out(vty, "%%Given ISDN user port already exists, remove first.%s", VTY_NEWLINE); return CMD_WARNING; } v5up = v5x_user_port_create(v5if, atoi(argv[0]), V5X_USER_TYPE_ISDN, 0, 0); if (!v5up) { vty_out(vty, "%%Failed to create ISDN user port.%s", VTY_NEWLINE); return CMD_WARNING; } return CMD_SUCCESS; } DEFUN(cfg_no_port_isdn, cfg_no_port_isdn_cmd, "no port isdn <0-8175>", NO_STR "Delete V5 user port\n" "ISDN user port\n" "L3 address\n") { struct v5x_interface *v5if = vty->index; struct v5x_user_port *v5up; v5up = v5x_user_port_find(v5if, atoi(argv[0]), true); if (!v5up) { vty_out(vty, "%%Given ISDN user port does not exist.%s", VTY_NEWLINE); return CMD_WARNING; } v5x_user_port_destroy(v5up); return CMD_SUCCESS; } static int config_write_interface_v51(struct vty *vty) { struct v5x_interface *v5if = NULL; struct v5x_user_port *v5up; if (!llist_empty(&v5i->interfaces)) v5if = (struct v5x_interface *)v5i->interfaces.next; vty_out(vty, "!%s", VTY_NEWLINE); if (!v5if) vty_out(vty, "no interface%s", VTY_NEWLINE); if (v5if && v5if->dialect == V5X_DIALECT_V51) { vty_out(vty, "interface v5.1%s", VTY_NEWLINE); vty_out(vty, " id %d%s", v5if->id, VTY_NEWLINE); vty_out(vty, " variant %d%s", v5if->variant, VTY_NEWLINE); llist_for_each_entry(v5up, &v5if->user_ports, list) { switch (v5up->type) { case V5X_USER_TYPE_PSTN: vty_out(vty, " port pstn %d %d%s", v5up->nr, v5up->ts_nr[0], VTY_NEWLINE); break; case V5X_USER_TYPE_ISDN: vty_out(vty, " port isdn %d %d %d%s", v5up->nr, v5up->ts_nr[0], v5up->ts_nr[1], VTY_NEWLINE); break; } } } return CMD_SUCCESS; } static int config_write_interface_v52(struct vty *vty) { struct v5x_interface *v5if = NULL; struct v5x_user_port *v5up; if (!llist_empty(&v5i->interfaces)) v5if = (struct v5x_interface *)v5i->interfaces.next; vty_out(vty, "!%s", VTY_NEWLINE); if (v5if && v5if->dialect == V5X_DIALECT_V52) { vty_out(vty, "interface v5.2%s", VTY_NEWLINE); vty_out(vty, " id %d%s", v5if->id, VTY_NEWLINE); vty_out(vty, " variant %d%s", v5if->variant, VTY_NEWLINE); llist_for_each_entry(v5up, &v5if->user_ports, list) { switch (v5up->type) { case V5X_USER_TYPE_PSTN: vty_out(vty, " port pstn %d%s", v5up->nr, VTY_NEWLINE); break; case V5X_USER_TYPE_ISDN: vty_out(vty, " port isdn %d%s", v5up->nr, VTY_NEWLINE); break; } } } return CMD_SUCCESS; } int v5x_vty_init(void) { install_element(CONFIG_NODE, &cfg_interface_cmd); install_element(CONFIG_NODE, &cfg_no_interface_cmd); install_node(&interface_node_v51, config_write_interface_v51); install_node(&interface_node_v52, config_write_interface_v52); install_element(INTERFACE_NODE_V51, &cfg_interface_id_cmd); install_element(INTERFACE_NODE_V51, &cfg_interface_variant_cmd); install_element(INTERFACE_NODE_V51, &cfg_port_pstn_cmd_v51); install_element(INTERFACE_NODE_V51, &cfg_no_port_pstn_cmd); install_element(INTERFACE_NODE_V51, &cfg_port_isdn_cmd_v51); install_element(INTERFACE_NODE_V51, &cfg_no_port_isdn_cmd); install_element(INTERFACE_NODE_V52, &cfg_interface_id_cmd); install_element(INTERFACE_NODE_V52, &cfg_interface_variant_cmd); install_element(INTERFACE_NODE_V52, &cfg_port_pstn_cmd_v52); install_element(INTERFACE_NODE_V52, &cfg_no_port_pstn_cmd); install_element(INTERFACE_NODE_V52, &cfg_port_isdn_cmd_v52); install_element(INTERFACE_NODE_V52, &cfg_no_port_isdn_cmd); return 0; }