2 * librouteros - src/routeros_api.h
3 * Copyright (C) 2009 Florian octo Forster
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 * Florian octo Forster <octo at verplant.org>
21 #ifndef ROUTEROS_API_H
22 #define ROUTEROS_API_H 1
27 #include <routeros_version.h>
29 #define ROUTEROS_API_PORT "8728"
32 * C++ doesn't have _Bool. We can't simply "#define _Bool bool", because we
33 * don't know if "bool" and "_Bool" are of the same size. If they are not, this
34 * would result in ABI incompatible code.
36 * So we're doing a best-effort solution here: If we're compiled with the GNU
37 * C++ compiler, g++, we include <stdbool.h>. The GCC will, as a GNU extension,
38 * define _Bool for C++. Since it's the compiler doing the definition, it's
39 * kind of save to assume that it will be done in an ABI compatible manner.
41 * If this results in any problems for you, define "ROS_HAVE_CPP_BOOL" to true
42 * to have this magic disabled. You will then have to define _Bool yourself.
44 * TODO: Write a test program for the configure sript to figure out the size of
45 * _Bool. Make this size available via <routeros_versioin.h> and define _Bool
46 * to short, long, ... here.
49 # if !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL
52 # endif /* __GNUC__ */
53 # endif /* !defined (ROS_HAVE_CPP_BOOL) || !ROS_HAVE_CPP_BOOL */
58 struct ros_connection_s;
59 typedef struct ros_connection_s ros_connection_t;
62 typedef struct ros_reply_s ros_reply_t;
64 typedef int (*ros_reply_handler_t) (ros_connection_t *c, const ros_reply_t *r,
70 ros_connection_t *ros_connect (const char *node, const char *service,
71 const char *username, const char *password);
72 int ros_disconnect (ros_connection_t *con);
77 int ros_query (ros_connection_t *c,
79 size_t args_num, const char * const *args,
80 ros_reply_handler_t handler, void *user_data);
85 const ros_reply_t *ros_reply_next (const ros_reply_t *r);
86 int ros_reply_num (const ros_reply_t *r);
88 const char *ros_reply_status (const ros_reply_t *r);
90 /* Receiving reply parameters */
91 const char *ros_reply_param_key_by_index (const ros_reply_t *r,
93 const char *ros_reply_param_val_by_index (const ros_reply_t *r,
95 const char *ros_reply_param_val_by_key (const ros_reply_t *r, const char *key);
97 /* High-level function for accessing /interface {{{ */
98 struct ros_interface_s;
99 typedef struct ros_interface_s ros_interface_t;
100 struct ros_interface_s
102 /* Name of the interface */
107 /* Packet, octet and error counters. */
117 /* Maximum transfer unit */
121 /* Interface flags */
127 const ros_interface_t *next;
130 /* Callback function */
131 typedef int (*ros_interface_handler_t) (ros_connection_t *c,
132 const ros_interface_t *i, void *user_data);
134 int ros_interface (ros_connection_t *c,
135 ros_interface_handler_t handler, void *user_data);
138 /* High-level function for accessing /interface/wireless/registration-table {{{ */
139 struct ros_registration_table_s;
140 typedef struct ros_registration_table_s ros_registration_table_t;
141 struct ros_registration_table_s
143 /* Name of the interface */
144 const char *interface;
145 /* Name of the remote radio */
146 const char *radio_name;
148 /* ap is set to true, if the REMOTE radio is an access point. */
152 /* Receive and transmit rate in MBit/s */
156 /* Packet, octet and frame counters. */
163 uint64_t rx_frame_bytes;
164 uint64_t tx_frame_bytes;
165 uint64_t rx_hw_frames;
166 uint64_t tx_hw_frames;
167 uint64_t rx_hw_frame_bytes;
168 uint64_t tx_hw_frame_bytes;
170 /* Signal quality information (in dBm) */
171 double rx_signal_strength;
172 double tx_signal_strength;
173 double signal_to_noise;
175 /* Overall connection quality (in percent) */
180 const ros_registration_table_t *next;
183 /* Callback function */
184 typedef int (*ros_registration_table_handler_t) (ros_connection_t *c,
185 const ros_registration_table_t *r, void *user_data);
187 int ros_registration_table (ros_connection_t *c,
188 ros_registration_table_handler_t handler, void *user_data);
189 /* }}} /interface/wireless/registration-table */
191 /* High-level function for accessing /system/resource {{{ */
192 struct ros_system_resource_s;
193 typedef struct ros_system_resource_s ros_system_resource_t;
194 struct ros_system_resource_s
199 const char *architecture_name;
200 const char *board_name;
202 const char *cpu_model;
203 unsigned int cpu_count;
204 unsigned int cpu_load;
205 uint64_t cpu_frequency;
207 uint64_t free_memory;
208 uint64_t total_memory;
210 uint64_t free_hdd_space;
211 uint64_t total_hdd_space;
213 uint64_t write_sect_since_reboot;
214 uint64_t write_sect_total;
218 /* Callback function */
219 typedef int (*ros_system_resource_handler_t) (ros_connection_t *c,
220 const ros_system_resource_t *r, void *user_data);
222 int ros_system_resource (ros_connection_t *c,
223 ros_system_resource_handler_t handler, void *user_data);
224 /* }}} /system/resource */
230 #endif /* ROUTEROS_API_H */
232 /* vim: set ts=2 sw=2 noet fdm=marker : */