2 * librouteros - src/routeros_api.h
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 ROUTEROS_API_H
23 #define ROUTEROS_API_H 1
28 #include <routeros_version.h>
30 #define ROUTEROS_API_PORT "8728"
33 * C++ doesn't have _Bool. We can't simply "#define _Bool bool", because we
34 * don't know if "bool" and "_Bool" are of the same size. If they are not, this
35 * would result in ABI incompatible code.
37 * So we're doing a best-effort solution here: If we're compiled with the GNU
38 * C++ compiler, g++, we include <stdbool.h>. The GCC will, as a GNU extension,
39 * define _Bool for C++. Since it's the compiler doing the definition, it's
40 * kind of save to assume that it will be done in an ABI compatible manner.
42 * If this results in any problems for you, define "ROS_HAVE_CPP_BOOL" to true
43 * to have this magic disabled. You will then have to define _Bool yourself.
45 * TODO: Write a test program for the configure sript to figure out the size of
46 * _Bool. Make this size available via <routeros_versioin.h> and define _Bool
47 * to short, long, ... here.
50 # if !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL
53 # endif /* __GNUC__ */
54 # endif /* !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL */
59 struct ros_connection_s;
60 typedef struct ros_connection_s ros_connection_t;
63 typedef struct ros_reply_s ros_reply_t;
65 typedef int (*ros_reply_handler_t) (ros_connection_t *c, const ros_reply_t *r,
71 ros_connection_t *ros_connect (const char *node, const char *service,
72 const char *username, const char *password);
73 int ros_disconnect (ros_connection_t *con);
78 int ros_query (ros_connection_t *c,
80 size_t args_num, const char * const *args,
81 ros_reply_handler_t handler, void *user_data);
86 const ros_reply_t *ros_reply_next (const ros_reply_t *r);
87 int ros_reply_num (const ros_reply_t *r);
89 const char *ros_reply_status (const ros_reply_t *r);
91 /* Receiving reply parameters */
92 const char *ros_reply_param_key_by_index (const ros_reply_t *r,
94 const char *ros_reply_param_val_by_index (const ros_reply_t *r,
96 const char *ros_reply_param_val_by_key (const ros_reply_t *r, const char *key);
98 /* High-level function for accessing /interface {{{ */
99 struct ros_interface_s;
100 typedef struct ros_interface_s ros_interface_t;
101 struct ros_interface_s
103 /* Name of the interface */
108 /* Packet, octet and error counters. */
118 /* Maximum transfer unit */
122 /* Interface flags */
128 const ros_interface_t *next;
131 /* Callback function */
132 typedef int (*ros_interface_handler_t) (ros_connection_t *c,
133 const ros_interface_t *i, void *user_data);
135 int ros_interface (ros_connection_t *c,
136 ros_interface_handler_t handler, void *user_data);
139 /* High-level function for accessing /interface/wireless/registration-table {{{ */
140 struct ros_registration_table_s;
141 typedef struct ros_registration_table_s ros_registration_table_t;
142 struct ros_registration_table_s
144 /* Name of the interface */
145 const char *interface;
146 /* Name of the remote radio */
147 const char *radio_name;
149 /* ap is set to true, if the REMOTE radio is an access point. */
153 /* Receive and transmit rate in MBit/s */
157 /* Packet, octet and frame counters. */
164 uint64_t rx_frame_bytes;
165 uint64_t tx_frame_bytes;
166 uint64_t rx_hw_frames;
167 uint64_t tx_hw_frames;
168 uint64_t rx_hw_frame_bytes;
169 uint64_t tx_hw_frame_bytes;
171 /* Signal quality information (in dBm) */
172 double rx_signal_strength;
173 double tx_signal_strength;
174 double signal_to_noise;
176 /* Overall connection quality (in percent) */
181 const ros_registration_table_t *next;
184 /* Callback function */
185 typedef int (*ros_registration_table_handler_t) (ros_connection_t *c,
186 const ros_registration_table_t *r, void *user_data);
188 int ros_registration_table (ros_connection_t *c,
189 ros_registration_table_handler_t handler, void *user_data);
190 /* }}} /interface/wireless/registration-table */
192 /* High-level function for accessing /system/resource {{{ */
193 struct ros_system_resource_s;
194 typedef struct ros_system_resource_s ros_system_resource_t;
195 struct ros_system_resource_s
200 const char *architecture_name;
201 const char *board_name;
203 const char *cpu_model;
204 unsigned int cpu_count;
205 unsigned int cpu_load;
206 uint64_t cpu_frequency;
208 uint64_t free_memory;
209 uint64_t total_memory;
211 uint64_t free_hdd_space;
212 uint64_t total_hdd_space;
214 uint64_t write_sect_since_reboot;
215 uint64_t write_sect_total;
219 /* Callback function */
220 typedef int (*ros_system_resource_handler_t) (ros_connection_t *c,
221 const ros_system_resource_t *r, void *user_data);
223 int ros_system_resource (ros_connection_t *c,
224 ros_system_resource_handler_t handler, void *user_data);
225 /* }}} /system/resource */
231 #endif /* ROUTEROS_API_H */
233 /* vim: set ts=2 sw=2 noet fdm=marker : */