"registration-table" interface: Add "radio-name", "ap", and "wds".
[routeros-api.git] / src / routeros_api.h
1 /**
2  * librouteros - src/routeros_api.h
3  * Copyright (C) 2009  Florian octo Forster
4  *
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.
8  *
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.
13  *
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
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef ROUTEROS_API_H
23 #define ROUTEROS_API_H 1
24
25 #include <stdint.h>
26 #include <inttypes.h>
27
28 #include <routeros_version.h>
29
30 #define ROUTEROS_API_PORT "8728"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct ros_connection_s;
37 typedef struct ros_connection_s ros_connection_t;
38
39 struct ros_reply_s;
40 typedef struct ros_reply_s ros_reply_t;
41
42 typedef int (*ros_reply_handler_t) (ros_connection_t *c, const ros_reply_t *r,
43                 void *user_data);
44
45 /*
46  * Connection handling
47  */
48 ros_connection_t *ros_connect (const char *node, const char *service,
49                 const char *username, const char *password);
50 int ros_disconnect (ros_connection_t *con);
51
52 /* 
53  * Command execution
54  */
55 int ros_query (ros_connection_t *c,
56                 const char *command,
57                 size_t args_num, const char * const *args,
58                 ros_reply_handler_t handler, void *user_data);
59
60 /* 
61  * Reply handling
62  */
63 const ros_reply_t *ros_reply_next (const ros_reply_t *r);
64 int ros_reply_num (const ros_reply_t *r);
65
66 const char *ros_reply_status (const ros_reply_t *r);
67
68 /* Receiving reply parameters */
69 const char *ros_reply_param_key_by_index (const ros_reply_t *r,
70                 unsigned int index);
71 const char *ros_reply_param_val_by_index (const ros_reply_t *r,
72                 unsigned int index);
73 const char *ros_reply_param_val_by_key (const ros_reply_t *r, const char *key);
74
75 /* High-level function for accessing /interface {{{ */
76 struct ros_interface_s;
77 typedef struct ros_interface_s ros_interface_t;
78 struct ros_interface_s
79 {
80         /* Name of the interface */
81         const char *name;
82         const char *type;
83         const char *comment;
84
85         /* Packet, octet and error counters. */
86         uint64_t rx_packets;
87         uint64_t tx_packets;
88         uint64_t rx_bytes;
89         uint64_t tx_bytes;
90         uint64_t rx_errors;
91         uint64_t tx_errors;
92         uint64_t rx_drops;
93         uint64_t tx_drops;
94
95         /* Maximum transfer unit */
96         unsigned int mtu;
97         unsigned int l2mtu;
98
99         /* Interface flags */
100         _Bool dynamic;
101         _Bool running;
102         _Bool enabled;
103
104         /* Next interface */
105         const ros_interface_t *next;
106 };
107
108 /* Callback function */
109 typedef int (*ros_interface_handler_t) (ros_connection_t *c,
110                 const ros_interface_t *i, void *user_data);
111
112 int ros_interface (ros_connection_t *c,
113                 ros_interface_handler_t handler, void *user_data);
114 /* }}} /interface */
115
116 /* High-level function for accessing /interface/wireless/registration-table {{{ */
117 struct ros_registration_table_s;
118 typedef struct ros_registration_table_s ros_registration_table_t;
119 struct ros_registration_table_s
120 {
121         /* Name of the interface */
122         const char *interface;
123         /* Name of the remote radio */
124         const char *radio_name;
125
126         /* ap is set to true, if the REMOTE radio is an access point. */
127         _Bool ap;
128         _Bool wds;
129
130         /* Receive and transmit rate in MBit/s */
131         double rx_rate;
132         double tx_rate;
133
134         /* Packet, octet and frame counters. */
135         uint64_t rx_packets;
136         uint64_t tx_packets;
137         uint64_t rx_bytes;
138         uint64_t tx_bytes;
139         uint64_t rx_frames;
140         uint64_t tx_frames;
141         uint64_t rx_frame_bytes;
142         uint64_t tx_frame_bytes;
143         uint64_t rx_hw_frames;
144         uint64_t tx_hw_frames;
145         uint64_t rx_hw_frame_bytes;
146         uint64_t tx_hw_frame_bytes;
147
148         /* Signal quality information (in dBm) */
149         double rx_signal_strength;
150         double tx_signal_strength;
151         double signal_to_noise;
152
153         /* Overall connection quality (in percent) */
154         double rx_ccq;
155         double tx_ccq;
156
157         /* Next interface */
158         const ros_registration_table_t *next;
159 };
160
161 /* Callback function */
162 typedef int (*ros_registration_table_handler_t) (ros_connection_t *c,
163                 const ros_registration_table_t *r, void *user_data);
164
165 int ros_registration_table (ros_connection_t *c,
166                 ros_registration_table_handler_t handler, void *user_data);
167 /* }}} /interface/wireless/registration-table */
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif /* ROUTEROS_API_H */
174
175 /* vim: set ts=2 sw=2 noet fdm=marker : */