2 * librouteros - src/registration_table.c
3 * Copyright (C) 2009 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
22 #ifndef _ISOC99_SOURCE
23 # define _ISOC99_SOURCE
26 #ifndef _POSIX_C_SOURCE
27 # define _POSIX_C_SOURCE 200112L
40 #include "routeros_api.h"
41 #include "ros_parse.h"
46 Param 1: interface = wlan2
47 Param 2: radio-name = 000C423AECCF
48 Param 3: mac-address = 00:0C:42:3A:EC:CF
51 Param 6: rx-rate = 58.5Mbps-HT
52 Param 7: tx-rate = 52.0Mbps-HT
53 Param 8: packets = 6962070,10208268
54 Param 9: bytes = 1090924066,2872515632
55 Param 10: frames = 6662813,9698341
56 Param 11: frame-bytes = 1111022872,2846535122
57 Param 12: hw-frames = 8338229,9718084
58 Param 13: hw-frame-bytes = 1941643579,3255546365
59 Param 14: tx-frames-timed-out = 0
60 Param 15: uptime = 2w6d13:21:53
61 Param 16: last-activity = 00:00:00.060
62 Param 17: signal-strength = -74dBm@6Mbps
63 Param 18: signal-to-noise = 42
64 Param 19: strength-at-rates = -74dBm@6Mbps 10ms,-78dBm@9Mbps 2w2d16h56m20s890ms,-78dBm@12Mbps 2w2d16h55m51s670ms,-77dBm@18Mbps 2w2d16h55m35s880ms,-78dBm@24Mbps 2w2d16h55m5s590ms,-75dBm@36Mbps 1d10h58m48s840ms,-75dBm@48Mbps 1d10h48m34s130ms,-77dBm@54Mbps 1d10h47m34s680ms,-73dBm@HT20-4 38m45s600ms,-73dBm@HT20-5 4m700ms,-74dBm@HT20-6 60ms,-78dBm@HT20-7 1d10h30m34s410ms
65 Param 20: tx-signal-strength = -76
68 Param 23: p-throughput = 36877
69 Param 24: ack-timeout = 30
70 Param 25: nstreme = false
71 Param 26: framing-mode = none
72 Param 27: routeros-version = 4.2
73 Param 28: last-ip = 62.128.1.53
74 Param 29: 802.1x-port-enabled = true
75 Param 30: authentication-type = wpa2-psk
76 Param 31: encryption = aes-ccm
77 Param 32: group-encryption = aes-ccm
78 Param 33: compression = false
79 Param 34: wmm-enabled = true
88 struct rt_internal_data_s
90 ros_registration_table_handler_t handler;
93 typedef struct rt_internal_data_s rt_internal_data_t;
98 static ros_registration_table_t *rt_reply_to_regtable (const ros_reply_t *r) /* {{{ */
100 ros_registration_table_t *ret;
105 if (strcmp ("re", ros_reply_status (r)) != 0)
106 return (rt_reply_to_regtable (ros_reply_next (r)));
108 ret = malloc (sizeof (*ret));
111 memset (ret, 0, sizeof (*ret));
113 ret->interface = ros_reply_param_val_by_key (r, "interface");
114 ret->radio_name = ros_reply_param_val_by_key (r, "radio-name");
116 ret->ap = sstrtob (ros_reply_param_val_by_key (r, "ap"));
117 ret->wds = sstrtob (ros_reply_param_val_by_key (r, "wds"));
119 ret->rx_rate = sstrtod (ros_reply_param_val_by_key (r, "rx-rate"));
120 ret->tx_rate = sstrtod (ros_reply_param_val_by_key (r, "tx-rate"));
122 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "packets"),
123 &ret->rx_packets, &ret->tx_packets);
124 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "bytes"),
125 &ret->rx_bytes, &ret->tx_bytes);
126 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "frames"),
127 &ret->rx_frames, &ret->tx_frames);
128 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "frame-bytes"),
129 &ret->rx_frame_bytes, &ret->tx_frame_bytes);
130 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frames"),
131 &ret->rx_hw_frames, &ret->tx_hw_frames);
132 sstrto_rx_tx_counters (ros_reply_param_val_by_key (r, "hw-frame-bytes"),
133 &ret->rx_hw_frame_bytes, &ret->tx_hw_frame_bytes);
135 ret->rx_signal_strength = sstrtod (ros_reply_param_val_by_key (r, "signal-strength"));
136 ret->tx_signal_strength = sstrtod (ros_reply_param_val_by_key (r, "tx-signal-strength"));
137 ret->signal_to_noise = sstrtod (ros_reply_param_val_by_key (r, "signal-to-noise"));
139 ret->rx_ccq = sstrtod (ros_reply_param_val_by_key (r, "rx-ccq"));
140 ret->tx_ccq = sstrtod (ros_reply_param_val_by_key (r, "tx-ccq"));
142 ret->next = rt_reply_to_regtable (ros_reply_next (r));
145 } /* }}} ros_registration_table_t *rt_reply_to_regtable */
147 static void rt_regtable_free (const ros_registration_table_t *r) /* {{{ */
149 const ros_registration_table_t *next;
157 } /* }}} void rt_regtable_free */
159 static int rt_internal_handler (ros_connection_t *c, /* {{{ */
160 const ros_reply_t *r, void *user_data)
162 ros_registration_table_t *rt_data;
163 rt_internal_data_t *internal_data;
166 rt_data = rt_reply_to_regtable (r);
170 internal_data = user_data;
172 status = internal_data->handler (c, rt_data, internal_data->user_data);
174 rt_regtable_free (rt_data);
177 } /* }}} int rt_internal_handler */
182 int ros_registration_table (ros_connection_t *c, /* {{{ */
183 ros_registration_table_handler_t handler, void *user_data)
185 rt_internal_data_t data;
187 if ((c == NULL) || (handler == NULL))
190 data.handler = handler;
191 data.user_data = user_data;
193 return (ros_query (c, "/interface/wireless/registration-table/print",
194 /* args_num = */ 0, /* args = */ NULL,
195 rt_internal_handler, &data));
196 } /* }}} int ros_registration_table */
198 /* vim: set ts=2 sw=2 noet fdm=marker : */