3 * Copyright (c) 2004, Andreas Tønnesen(andreto-at-olsr.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of the UniK olsr daemon nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 /* $Id: olsrd_plugin.h,v 1.3 2004/11/07 10:54:19 kattemat Exp $ */
35 * Dynamic linked library example for UniK OLSRd
38 #ifndef _OLSRD_PLUGIN_DEFS
39 #define _OLSRD_PLUGIN_DEFS
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
49 #include "olsr_plugin_io.h"
51 /* Use this as PARSER_TYPE to receive ALL messages! */
52 #define PROMISCUOUS 0xffffffff
55 /*****************************************************************************
57 * ALTER THIS TO YOUR OWN NEED *
58 *****************************************************************************/
60 #define PLUGIN_NAME "OLSRD Powerstatus plugin"
61 #define PLUGIN_VERSION "0.3"
62 #define PLUGIN_AUTHOR "Andreas Tønnesen"
63 #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
64 #define PLUGIN_INTERFACE_VERSION 2
66 /* The type of message you will use */
67 #define MESSAGE_TYPE 128
69 /* The type of messages we will receive - can be set to promiscuous */
70 #define PARSER_TYPE MESSAGE_TYPE
74 /****************************************************************************
75 * Various datastructures and definitions from olsrd *
76 ****************************************************************************/
83 #include <sys/types.h>
85 typedef u_int8_t olsr_u8_t;
86 typedef u_int16_t olsr_u16_t;
87 typedef u_int32_t olsr_u32_t;
88 typedef int8_t olsr_8_t;
89 typedef int16_t olsr_16_t;
90 typedef int32_t olsr_32_t;
112 #define UNSPEC_LINK 0
126 #define HASHMASK (HASHSIZE - 1)
128 #define MAXIFS 8 /* Maximum number of interfaces (from defs.h) in uOLSRd */
131 /****************************************************************************
132 * INTERFACE SECTION *
133 ****************************************************************************/
143 *A struct containing all necessary information about each
144 *interface participating in the OLSD routing
149 struct sockaddr int_addr; /* address */
150 struct sockaddr int_netmask; /* netmask */
151 struct sockaddr int_broadaddr; /* broadcast address */
153 struct sockaddr_in6 int6_addr; /* Address */
154 struct sockaddr_in6 int6_multaddr; /* Multicast */
156 union olsr_ip_addr ip_addr;
157 int olsr_socket; /* The broadcast socket for this interface */
158 int int_metric; /* metric of interface */
159 int int_mtu; /* MTU of interface */
160 int int_flags; /* see below */
161 char *int_name; /* from kernel if structure */
162 int if_index; /* Kernels index of this interface */
163 int if_nr; /* This interfaces index internally*/
164 int is_wireless; /* wireless interface or not*/
165 olsr_u16_t olsr_seqnum; /* Olsr message seqno */
168 struct vtimes valtimes;
170 struct interface *int_next;
176 /****************************************************************************
177 * POWERSTATUS SECTION *
178 ****************************************************************************/
180 #define OLSR_BATTERY_POWERED 0
181 #define OLSR_AC_POWERED 1
186 int battery_percentage;
189 /****************************************************************************
191 ****************************************************************************/
194 /**********************************
195 * DEFINE YOUR CUSTOM PACKET HERE *
196 **********************************/
200 olsr_u8_t source_type;
201 olsr_u8_t percentage;
202 olsr_u16_t time_left;
206 * OLSR message (several can exist in one OLSR packet)
211 olsr_u8_t olsr_msgtype;
212 olsr_u8_t olsr_vtime;
213 olsr_u16_t olsr_msgsize;
214 olsr_u32_t originator;
219 /* YOUR PACKET GOES HERE */
230 olsr_u8_t olsr_msgtype;
231 olsr_u8_t olsr_vtime;
232 olsr_u16_t olsr_msgsize;
233 struct in6_addr originator;
238 /* YOUR PACKET GOES HERE */
244 * ALWAYS USE THESE WRAPPERS TO
245 * ENSURE IPv4 <-> IPv6 compability
257 /***************************************************************************
258 * Functions provided by uolsrd_plugin.c *
259 * Similar to their siblings in olsrd *
260 ***************************************************************************/
262 char ipv6_buf[100]; /* buffer for IPv6 inet_htop */
264 /* All these could optionally be fetched from olsrd */
267 olsr_hashing(union olsr_ip_addr *);
270 olsr_get_timestamp(olsr_u32_t, struct timeval *);
273 olsr_init_timer(olsr_u32_t, struct timeval *);
276 olsr_timed_out(struct timeval *);
279 olsr_ip_to_string(union olsr_ip_addr *);
283 /****************************************************************************
284 * Function pointers to functions in olsrd *
285 * These allow direct access to olsrd functions *
286 ****************************************************************************/
288 /* The multi-purpose funtion. All other functions are fetched trough this */
289 int (*olsr_plugin_io)(int, void *, size_t);
291 /* add a prser function */
292 void (*olsr_parser_add_function)(void (*)(union olsr_message *, struct interface *, union olsr_ip_addr *), int, int);
294 /* Register a timeout function */
295 int (*olsr_register_timeout_function)(void (*)());
297 /* Register a scheduled event */
298 int (*olsr_register_scheduler_event)(void (*)(), void *, float, float, olsr_u8_t *);
300 /* Get the next message seqno in line */
301 olsr_u16_t (*get_msg_seqno)();
303 int (*net_outbuffer_push)(struct interface *, olsr_u8_t *, olsr_u16_t);
305 /* Transmit package */
306 int (*net_output)(struct interface*);
308 /* Check the duplicate table for prior processing */
309 int (*check_dup_proc)(union olsr_ip_addr *, olsr_u16_t);
311 /* Default forward algorithm */
312 int (*default_fwd)(union olsr_message *,
313 union olsr_ip_addr *,
316 union olsr_ip_addr *);
318 /* Add a socket to the main olsrd select loop */
319 void (*add_olsr_socket)(int, void(*)(int));
321 /* get the link status to a neighbor */
322 int (*check_neighbor_link)(union olsr_ip_addr *);
324 /* Mantissa/exponen conversions */
325 olsr_u8_t (*double_to_me)(double);
327 double (*me_to_double)(olsr_u8_t);
329 /* olsrd printf wrapper */
330 int (*olsr_printf)(int, char *, ...);
332 /* olsrd malloc wrapper */
333 void *(*olsr_malloc)(size_t, const char *);
335 int (*apm_read)(struct olsr_apm_info *);
338 /****************************************************************************
340 * NOTE THAT POINTERS POINT TO THE DATA USED BY OLSRD! *
341 * NEVER ALTER DATA POINTED TO BY THESE POINTERS *
342 * UNLESS YOU KNOW WHAT YOU ARE DOING!!! *
343 ****************************************************************************/
345 * The interface list from olsrd
348 struct interface *ifs;
350 /* These two are set automatically by olsrd at load time */
351 int ipversion; /* IPversion in use */
352 union olsr_ip_addr *main_addr; /* Main address */
355 size_t ipsize; /* Size of the ipadresses used */
356 struct timeval *now; /* the olsrds schedulers idea of current time */
359 /****************************************************************************
360 * Functions that the plugin MUST provide *
361 ****************************************************************************/
364 /* Initialization function */
368 /* IPC initialization function */
372 /* Destructor function */
376 /* Mulitpurpose funtion */
378 plugin_io(int, void *, size_t);
380 /* Plugin interface version */
382 get_plugin_interface_version();