Added first high-level interface for the registration table.
[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 <routeros_version.h>
26
27 #define ROUTEROS_API_PORT "8728"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 struct ros_connection_s;
34 typedef struct ros_connection_s ros_connection_t;
35
36 struct ros_reply_s;
37 typedef struct ros_reply_s ros_reply_t;
38
39 typedef int (*ros_reply_handler_t) (ros_connection_t *c, const ros_reply_t *r,
40                 void *user_data);
41
42 /*
43  * Connection handling
44  */
45 ros_connection_t *ros_connect (const char *node, const char *service,
46                 const char *username, const char *password);
47 int ros_disconnect (ros_connection_t *con);
48
49 /* 
50  * Command execution
51  */
52 int ros_query (ros_connection_t *c,
53                 const char *command,
54                 size_t args_num, const char * const *args,
55                 ros_reply_handler_t handler, void *user_data);
56
57 /* 
58  * Reply handling
59  */
60 const ros_reply_t *ros_reply_next (const ros_reply_t *r);
61 int ros_reply_num (const ros_reply_t *r);
62
63 const char *ros_reply_status (const ros_reply_t *r);
64
65 /* Receiving reply parameters */
66 const char *ros_reply_param_key_by_index (const ros_reply_t *r,
67                 unsigned int index);
68 const char *ros_reply_param_val_by_index (const ros_reply_t *r,
69                 unsigned int index);
70 const char *ros_reply_param_val_by_key (const ros_reply_t *r, const char *key);
71
72 /*
73  * High-level function for accessing /interface/wireless/registration-table
74  */
75 struct ros_registration_table_s;
76 typedef struct ros_registration_table_s ros_registration_table_t;
77 struct ros_registration_table_s
78 {
79         /* Name of the interface */
80         const char *interface;
81
82         /* Receive and transmit rate in MBit/s */
83         double rx_rate;
84         double tx_rate;
85
86         /* Packet, octet and frame counters. */
87         uint64_t rx_packets;
88         uint64_t tx_packets;
89         uint64_t rx_bytes;
90         uint64_t tx_bytes;
91         uint64_t rx_frames;
92         uint64_t tx_frames;
93         uint64_t rx_frame_bytes;
94         uint64_t tx_frame_bytes;
95         uint64_t rx_hw_frames;
96         uint64_t tx_hw_frames;
97         uint64_t rx_hw_frame_bytes;
98         uint64_t tx_hw_frame_bytes;
99
100         /* Signal quality information (in dBm) */
101         double rx_signal_strength;
102         double tx_signal_strength;
103         double signal_to_noise;
104
105         /* Overall connection quality (in percent) */
106         double rx_ccq;
107         double tx_ccq;
108
109         /* Next interface */
110         ros_registration_table_t *next;
111 };
112
113 /* Callback function */
114 typedef int (*ros_registration_table_handler) (ros_connection_t *c,
115                 const ros_registration_table_t *r, void *user_data);
116
117 int ros_registration_table (ros_connection_t *c,
118                 ros_registration_table_handler handler, void *user_data);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* ROUTEROS_API_H */
125
126 /* vim: set ts=2 sw=2 noet fdm=marker : */