diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 9 | ||||
-rw-r--r-- | src/Makefile.am | 24 | ||||
-rw-r--r-- | src/dect-cell-add.c | 67 | ||||
-rw-r--r-- | src/dect-cell-delete.c | 59 | ||||
-rw-r--r-- | src/dect-cell-list.c | 24 | ||||
-rw-r--r-- | src/dect-cluster-add.c | 95 | ||||
-rw-r--r-- | src/dect-cluster-delete.c | 64 | ||||
-rw-r--r-- | src/dect-cluster-list.c | 20 | ||||
-rw-r--r-- | src/dect-llme-mac-con.c | 111 | ||||
-rw-r--r-- | src/dect-llme-monitor.c | 37 | ||||
-rw-r--r-- | src/dect-llme-scan.c | 139 | ||||
-rw-r--r-- | src/dect-transceiver-bind.c | 62 | ||||
-rw-r--r-- | src/dect-transceiver-list.c | 60 |
13 files changed, 769 insertions, 2 deletions
diff --git a/src/.gitignore b/src/.gitignore index 3e091cb..1624901 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -38,6 +38,15 @@ nl-rule-list nl-tctree-list nl-util-addr nf-queue +dect-transceiver-list +dect-transceiver-bind +dect-cell-add +dect-cell-delete +dect-cell-list +dect-cluster-add +dect-cluster-delete +dect-cluster-list +dect-llme-scan nl-classid-lookup nl-pktloc-lookup nl-link-enslave diff --git a/src/Makefile.am b/src/Makefile.am index c318dcc..aa6ffe7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,8 @@ LDADD = \ ${top_builddir}/lib/libnl-3.la \ ${top_builddir}/lib/libnl-nf-3.la \ ${top_builddir}/lib/libnl-genl-3.la \ - ${top_builddir}/lib/libnl-route-3.la + ${top_builddir}/lib/libnl-route-3.la \ + $(top_builddir)/lib/libnl-dect-3.la sbin_PROGRAMS = \ genl-ctrl-list \ @@ -36,7 +37,11 @@ noinst_PROGRAMS = \ nl-list-caches nl-list-sockets \ nl-util-addr \ nl-link-enslave \ - nl-link-release + nl-link-release \ + dect-transceiver-bind dect-transceiver-list \ + dect-cell-add dect-cell-delete dect-cell-list \ + dect-cluster-add dect-cluster-delete dect-cluster-list \ + dect-llme-monitor dect-llme-scan genl_ctrl_list_SOURCES = genl-ctrl-list.c @@ -96,5 +101,20 @@ nl_list_sockets_SOURCES = nl-list-sockets.c nl_util_addr_SOURCES = nl-util-addr.c nl_pktloc_lookup_SOURCES = nl-pktloc-lookup.c +nl_pktloc_lookup_LDADD = -lnl-route nl_classid_lookup_SOURCES = nl-classid-lookup.c + +dect_transceiver_bind_SOURCES = dect-transceiver-bind.c +dect_transceiver_list_SOURCES = dect-transceiver-list.c + +dect_cell_add_SOURCES = dect-cell-add.c +dect_cell_delete_SOURCES = dect-cell-delete.c +dect_cell_list_SOURCES = dect-cell-list.c + +dect_cluster_add_SOURCES = dect-cluster-add.c +dect_cluster_delete_SOURCES = dect-cluster-delete.c +dect_cluster_list_SOURCES = dect-cluster-list.c + +dect_llme_monitor_SOURCES = dect-llme-monitor.c +dect_llme_scan_SOURCES = dect-llme-scan.c diff --git a/src/dect-cell-add.c b/src/dect-cell-add.c new file mode 100644 index 0000000..f9448a0 --- /dev/null +++ b/src/dect-cell-add.c @@ -0,0 +1,67 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_dect_cell *cell; + struct nl_cache *cluster_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + uint8_t cli; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + + cell = nl_dect_cell_alloc(); + for (;;) { + int c, optidx = 0; + enum { + ARG_NAME = 256, + ARG_FLAGS, + ARG_CLUSTER, + }; + static struct option long_opts[] = { + { "name", 1, 0, ARG_NAME }, + { "flags", 1, 0, ARG_FLAGS }, + { "cluster", 1, 0, ARG_CLUSTER }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_NAME: + nl_dect_cell_set_name(cell, optarg); + break; + case ARG_FLAGS: + nl_dect_cell_set_flags(cell, nl_dect_cell_str2flags(optarg)); + break; + case ARG_CLUSTER: + if (isdigit(*optarg)) + cli = strtoul(optarg, NULL, 0); + else + cli = nl_dect_cluster_name2i(cluster_cache, optarg); + nl_dect_cell_set_link(cell, cli); + break; + } + } + + err = nl_dect_cell_add(sock, cell, 0); + if (err < 0) + nl_cli_fatal(err, "Unable to add cell: %s", nl_geterror(err)); + + printf("Added: "); + nl_object_dump(OBJ_CAST(cell), ¶ms); + return 0; +} + diff --git a/src/dect-cell-delete.c b/src/dect-cell-delete.c new file mode 100644 index 0000000..2cb2747 --- /dev/null +++ b/src/dect-cell-delete.c @@ -0,0 +1,59 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_dect_cell *cell; + struct nl_cache *cluster_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + + cell = nl_dect_cell_alloc(); + for (;;) { + int c, optidx = 0; + enum { + ARG_CELL = 257, + ARG_CLUSTER, + ARG_TRANSCEIVER, + }; + static struct option long_opts[] = { + { "cell", 1, 0, ARG_CELL }, + { "cluster", 1, 0, ARG_CLUSTER }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_CELL: + nl_dect_cell_set_name(cell, optarg); + break; + case ARG_CLUSTER: + nl_dect_cell_set_link(cell, + nl_dect_cluster_name2i(cluster_cache, optarg)); + break; + } + } + + err = nl_dect_cell_delete(sock, cell, 0); + if (err < 0) + nl_cli_fatal(err, "Unable to delete cell: %s", nl_geterror(err)); + + printf("Deleted: "); + nl_object_dump(OBJ_CAST(cell), ¶ms); + return 0; +} + diff --git a/src/dect-cell-list.c b/src/dect-cell-list.c new file mode 100644 index 0000000..bb946ed --- /dev/null +++ b/src/dect-cell-list.c @@ -0,0 +1,24 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cell_cache; + struct nl_cache *cluster_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + if (nl_dect_cell_alloc_cache(sock, &cell_cache)) + exit(1); + + nl_cache_dump(cell_cache, ¶ms); + return 0; +} + diff --git a/src/dect-cluster-add.c b/src/dect-cluster-add.c new file mode 100644 index 0000000..12db751 --- /dev/null +++ b/src/dect-cluster-add.c @@ -0,0 +1,95 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_dect_cluster *cl; + struct nl_dect_ari *pari; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + cl = nl_dect_cluster_alloc(); + pari = (void *)nl_dect_cluster_get_pari(cl); + + for (;;) { + int c, optidx = 0; + enum { + ARG_NAME = 257, + ARG_MODE, + ARG_CLASS, + ARG_EMC, + ARG_EIC, + ARG_POC, + ARG_GOP, + ARG_FIL, + ARG_FPS, + ARG_FPN, + }; + static struct option long_opts[] = { + { "name", 1, 0, ARG_NAME }, + { "mode", 1, 0, ARG_MODE }, + { "class", 1, 0, ARG_CLASS }, + { "emc", 1, 0, ARG_EMC }, + { "eic", 1, 0, ARG_EIC }, + { "poc", 1, 0, ARG_POC }, + { "gop", 1, 0, ARG_GOP }, + { "fil", 1, 0, ARG_FIL }, + { "fps", 1, 0, ARG_FPS }, + { "fpn", 1, 0, ARG_FPN }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_NAME: + nl_dect_cluster_set_name(cl, strdup(optarg)); + break; + case ARG_MODE: + nl_dect_cluster_set_mode(cl, nl_dect_cluster_str2mode(optarg)); + break; + case ARG_CLASS: + nl_dect_ari_set_class(pari, nl_dect_ari_str2class(optarg)); + break; + case ARG_EMC: + nl_dect_ari_set_emc(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_EIC: + nl_dect_ari_set_eic(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_POC: + nl_dect_ari_set_poc(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_GOP: + nl_dect_ari_set_gop(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_FIL: + nl_dect_ari_set_fil(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPS: + nl_dect_ari_set_fps(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPN: + nl_dect_ari_set_fpn(pari, strtoul(optarg, NULL, 16)); + break; + } + } + + nl_dect_cluster_set_pari(cl, pari); + err = nl_dect_cluster_add(sock, cl, 0); + if (err < 0) + nl_cli_fatal(err, "Unable to add cluster: %s", nl_geterror(err)); + + printf("Added: "); + nl_object_dump(OBJ_CAST(cl), ¶ms); + return 0; +} + diff --git a/src/dect-cluster-delete.c b/src/dect-cluster-delete.c new file mode 100644 index 0000000..6e564ce --- /dev/null +++ b/src/dect-cluster-delete.c @@ -0,0 +1,64 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_dect_cluster *cl; + struct nl_dect_ari *pari; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + cl = nl_dect_cluster_alloc(); + pari = (void *)nl_dect_cluster_get_pari(cl); + + for (;;) { + int c, optidx = 0; + enum { + ARG_NAME = 257, + ARG_MODE, + ARG_EMC, + ARG_FPN, + }; + static struct option long_opts[] = { + { "name", 1, 0, ARG_NAME }, + { "mode", 1, 0, ARG_MODE }, + { "emc", 1, 0, ARG_EMC }, + { "fpn", 1, 0, ARG_FPN }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_NAME: + nl_dect_cluster_set_name(cl, strdup(optarg)); + break; + case ARG_MODE: + nl_dect_cluster_set_mode(cl, atoi(optarg)); + break; + case ARG_EMC: + nl_dect_ari_set_emc(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPN: + nl_dect_ari_set_fpn(pari, strtoul(optarg, NULL, 16)); + break; + } + } + + err = nl_dect_cluster_delete(sock, cl, 0); + if (err < 0) + nl_cli_fatal(err, "Unable to delete cluster: %s", nl_geterror(err)); + + printf("Deleted: "); + nl_object_dump(OBJ_CAST(cl), ¶ms); + return 0; +} + diff --git a/src/dect-cluster-list.c b/src/dect-cluster-list.c new file mode 100644 index 0000000..edff5fe --- /dev/null +++ b/src/dect-cluster-list.c @@ -0,0 +1,20 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cluster_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + + nl_cache_dump(cluster_cache, ¶ms); + return 0; +} + diff --git a/src/dect-llme-mac-con.c b/src/dect-llme-mac-con.c new file mode 100644 index 0000000..5acf6a7 --- /dev/null +++ b/src/dect-llme-mac-con.c @@ -0,0 +1,111 @@ +#if 0 +#include "utils.h" + +static void obj_input(struct nl_object *obj, void *arg) +{ + struct nl_dump_params dp = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + + printf("MAC Connection: "); + nl_object_dump(obj, &dp); + printf("\n"); +} + +static int event_input(struct nl_msg *msg, void *arg) +{ + if (nl_msg_parse(msg, &obj_input, NULL) < 0) + fprintf(stderr, "Unknown message type\n"); + return NL_STOP; +} + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cluster_cache; + struct dect_llme_msg *lmsg; + struct dect_ari *ari; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int index; + int err; + + sock = nlt_alloc_socket(); + nlt_connect(sock, NETLINK_DECT); + if (dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + + lmsg = dect_llme_msg_alloc(); + dect_llme_msg_set_type(lmsg, DECT_LLME_MAC_CON); + + ari = (void *)dect_llme_mac_con_get_ari(lmsg); + + for (;;) { + int c, optidx = 0; + enum { + ARG_CLUSTER = 257, + ARG_MCEI, + ARG_PMID, + ARG_EMC, + ARG_FPN, + ARG_FPC, + }; + static struct option long_opts[] = { + { "cluster", 1, 0, ARG_CLUSTER }, + { "mcei", 1, 0, ARG_MCEI }, + { "pmid", 1, 0, ARG_PMID }, + { "emc", 1, 0, ARG_EMC }, + { "fpn", 1, 0, ARG_FPN }, + { "fpc", 0, 0, ARG_FPC }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nlt_print_version(); break; + case ARG_CLUSTER: + index = dect_cluster_name2i(cluster_cache, optarg); + dect_llme_msg_set_index(lmsg, index); + break; + case ARG_MCEI: + dect_llme_mac_con_set_mcei(lmsg, strtoul(optarg, NULL, 16)); + break; + case ARG_PMID: + dect_llme_mac_con_set_pmid(lmsg, strtoul(optarg, NULL, 16)); + break; + case ARG_EMC: + dect_ari_set_emc(ari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPN: + dect_ari_set_fpn(ari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPC: + dect_llme_mac_info_set_fpc(lmsg, 0); + dect_llme_mac_info_set_ehlc(lmsg, 0); + break; + } + } + + //dect_llme_mac_con_set_ari(lmsg, ari); + if ((err = dect_llme_request(sock, lmsg)) < 0) + fatal(err, "Unable to send request: %s", nl_geterror(err)); + + printf("Requested: "); + nl_object_dump(OBJ_CAST(lmsg), ¶ms); + + nl_socket_add_membership(sock, DECTNLGRP_LLME); + nl_socket_disable_seq_check(sock); + nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); + while (1) + nl_recvmsgs_default(sock); + return 0; +} +#endif +int main() {} diff --git a/src/dect-llme-monitor.c b/src/dect-llme-monitor.c new file mode 100644 index 0000000..eba1536 --- /dev/null +++ b/src/dect-llme-monitor.c @@ -0,0 +1,37 @@ +#include "netlink/cli/utils.h" + +static void obj_input(struct nl_object *obj, void *arg) +{ + struct nl_dump_params dp = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + nl_object_dump(obj, &dp); +} + +static int event_input(struct nl_msg *msg, void *arg) +{ + if (nl_msg_parse(msg, &obj_input, NULL) < 0) + fprintf(stderr, "Unknown message type\n"); + return NL_STOP; +} + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cluster_cache; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + + nl_socket_add_membership(sock, DECTNLGRP_LLME); + nl_socket_disable_seq_check(sock); + nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); + while (1) + nl_recvmsgs_default(sock); + return 0; +} + diff --git a/src/dect-llme-scan.c b/src/dect-llme-scan.c new file mode 100644 index 0000000..1d4980f --- /dev/null +++ b/src/dect-llme-scan.c @@ -0,0 +1,139 @@ +#include "netlink/cli/utils.h" + +#define CACHE_SIZE 64 + +static struct { + unsigned int index; + unsigned int used; + struct { + uint16_t emc; + uint32_t fpn; + uint8_t rpn; + } ids[CACHE_SIZE]; +} cache; + +static void add_ari(const struct nl_dect_llme_msg *lmsg) +{ + const struct nl_dect_ari *ari = nl_dect_llme_mac_info_get_pari(lmsg); + unsigned int index = cache.index; + + cache.ids[index].emc = nl_dect_ari_get_emc(ari); + cache.ids[index].fpn = nl_dect_ari_get_fpn(ari); + cache.ids[index].rpn = nl_dect_llme_mac_info_get_rpn(lmsg); + + if (++cache.used > CACHE_SIZE) + cache.used = CACHE_SIZE; + if (++cache.index == CACHE_SIZE) + cache.index = 0; +} + +static bool lookup_ari(const struct nl_dect_llme_msg *lmsg) +{ + const struct nl_dect_ari *ari = nl_dect_llme_mac_info_get_pari(lmsg); + unsigned int index; + + for (index = 0; index < cache.used; index++) { + if (cache.ids[index].emc == nl_dect_ari_get_emc(ari) && + cache.ids[index].fpn == nl_dect_ari_get_fpn(ari) && + cache.ids[index].rpn == nl_dect_llme_mac_info_get_rpn(lmsg)) + return true; + } + return false; +} + +static void obj_input(struct nl_object *obj, void *arg) +{ + struct nl_dect_llme_msg *lmsg = nl_object_priv(obj); + struct nl_dump_params dp = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + static unsigned int n; + + if (lookup_ari(lmsg)) + return; + add_ari(lmsg); + + printf("%u: Station: ", ++n); + nl_object_dump(obj, &dp); + printf("\n"); +} + +static int event_input(struct nl_msg *msg, void *arg) +{ + if (nl_msg_parse(msg, &obj_input, NULL) < 0) + fprintf(stderr, "Unknown message type\n"); + return NL_OK; +} + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cluster_cache; + struct nl_dect_llme_msg *lmsg; + struct nl_dect_ari *pari; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int index; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + if (nl_dect_cluster_alloc_cache(sock, &cluster_cache)) + exit(1); + nl_cache_mngt_provide(cluster_cache); + + lmsg = nl_dect_llme_msg_alloc(); + nl_dect_llme_msg_set_type(lmsg, DECT_LLME_SCAN); + + pari = (void *)nl_dect_llme_mac_info_get_pari(lmsg); + + for (;;) { + int c, optidx = 0; + enum { + ARG_CLUSTER = 257, + ARG_EMC, + ARG_FPN, + }; + static struct option long_opts[] = { + { "cluster", 1, 0, ARG_CLUSTER }, + { "emc", 1, 0, ARG_EMC }, + { "fpn", 1, 0, ARG_FPN }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_CLUSTER: + index = nl_dect_cluster_name2i(cluster_cache, optarg); + nl_dect_llme_msg_set_index(lmsg, index); + break; + case ARG_EMC: + nl_dect_ari_set_emc(pari, strtoul(optarg, NULL, 16)); + break; + case ARG_FPN: + nl_dect_ari_set_fpn(pari, strtoul(optarg, NULL, 16)); + break; + } + } + + //nl_dect_llme_mac_info_set_pari(lmsg, pari); + if ((err = nl_dect_llme_request(sock, lmsg)) < 0) + nl_cli_fatal(err, "Unable to send request: %s", nl_geterror(err)); + + printf("Requested: "); + nl_object_dump(OBJ_CAST(lmsg), ¶ms); + + nl_socket_disable_seq_check(sock); + nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); + while (1) + nl_recvmsgs_default(sock); + return 0; +} + diff --git a/src/dect-transceiver-bind.c b/src/dect-transceiver-bind.c new file mode 100644 index 0000000..97ad77e --- /dev/null +++ b/src/dect-transceiver-bind.c @@ -0,0 +1,62 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_dect_transceiver *trx; + struct nl_cache *cell_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + int err; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + + if (nl_dect_cell_alloc_cache(sock, &cell_cache)) + exit(1); + nl_cache_mngt_provide(cell_cache); + + trx = nl_dect_transceiver_alloc(); + for (;;) { + int c, optidx = 0; + enum { + ARG_TRANSCEIVER = 257, + ARG_CELL, + ARG_UNBIND, + }; + static struct option long_opts[] = { + { "transceiver", 1, 0, ARG_TRANSCEIVER }, + { "cell", 1, 0, ARG_CELL }, + { "unbind", 0, 0, ARG_UNBIND }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'v': nl_cli_print_version(); break; + case ARG_TRANSCEIVER: + nl_dect_transceiver_set_name(trx, strdup(optarg)); + break; + case ARG_CELL: + nl_dect_transceiver_set_link(trx, nl_dect_cell_name2i(cell_cache, optarg)); + break; + case ARG_UNBIND: + nl_dect_transceiver_set_link(trx, -1); + break; + } + } + + err = nl_dect_transceiver_change(sock, trx, 0); + if (err < 0) + nl_cli_fatal(err, "Unable to bind to cell: %s", nl_geterror(err)); + + printf("Bound: "); + nl_object_dump(OBJ_CAST(trx), ¶ms); + return 0; +} + diff --git a/src/dect-transceiver-list.c b/src/dect-transceiver-list.c new file mode 100644 index 0000000..c1e5cde --- /dev/null +++ b/src/dect-transceiver-list.c @@ -0,0 +1,60 @@ +#include "netlink/cli/utils.h" + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *cell_cache; + struct nl_cache *transceiver_cache; + struct nl_dect_transceiver *trx; + struct nl_dump_params params = { + .dp_type = NL_DUMP_LINE, + .dp_fd = stdout, + }; + + sock = nl_cli_alloc_socket(); + nl_cli_connect(sock, NETLINK_DECT); + + if (nl_dect_cell_alloc_cache(sock, &cell_cache)) + exit(1); + nl_cache_mngt_provide(cell_cache); + + if (nl_dect_transceiver_alloc_cache(sock, &transceiver_cache)) + exit(1); + trx = nl_dect_transceiver_alloc(); + if (trx == NULL) + exit(1); + + for (;;) { + int c, optidx = 0, cidx; + enum { + ARG_NAME = 257, + ARG_CELL, + }; + static struct option long_ops[] = { + { "name", 1, 0, ARG_NAME }, + { "cell", 1, 0, ARG_CELL }, + {} + }; + + c = getopt_long(argc, argv, "n:c:", long_ops, &optidx); + if (c == -1) + break; + switch (c) { + case ARG_NAME: + nl_dect_transceiver_set_name(trx, optarg); + break; + case ARG_CELL: + cidx = nl_dect_cell_name2i(cell_cache, optarg); + if (cidx == 0) { + fprintf(stderr, "cell %s does not exist\n", optarg); + exit(1); + } + nl_dect_transceiver_set_link(trx, cidx); + break; + } + } + + nl_cache_dump_filter(transceiver_cache, ¶ms, OBJ_CAST(trx)); + return 0; +} + |