Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / shared / shared.h
blob9838b6876c374a592b3abe0174155edf908f5b02
1 #ifndef __SHARED_H__
2 #define __SHARED_H__
4 #include <tomato_profile.h>
5 #include <tomato_config.h>
7 #include <netinet/in.h>
8 #include <stdint.h>
9 #include <errno.h>
10 #include <net/if.h>
12 #ifdef TCONFIG_USB
13 #include <mntent.h> // !!TB
14 #endif
16 #define Y2K 946684800UL // seconds since 1970
18 #define ASIZE(array) (sizeof(array) / sizeof(array[0]))
20 #ifdef LINUX26
21 #define MTD_DEV(arg) "/dev/mtd"#arg
22 #define MTD_BLKDEV(arg) "/dev/mtdblock"#arg
23 #define DEV_GPIO(arg) "/dev/gpio"#arg
24 #else
25 #define MTD_DEV(arg) "/dev/mtd/"#arg
26 #define MTD_BLKDEV(arg) "/dev/mtdblock/"#arg
27 #define DEV_GPIO(arg) "/dev/gpio/"#arg
28 #endif
30 //version.c
31 extern const char *tomato_version;
32 extern const char *tomato_buildtime;
33 extern const char *tomato_shortver;
36 #ifdef DEBUG_NOISY
37 #define _dprintf cprintf
38 #else
39 #define _dprintf(args...) do { } while(0)
40 #endif
43 // misc.c
44 #define WP_DISABLED 0 // order must be synced with def in misc.c
45 #define WP_STATIC 1
46 #define WP_DHCP 2
47 #define WP_L2TP 3
48 #define WP_PPPOE 4
49 #define WP_PPTP 5
50 #define WP_PPP3G 6
52 #ifdef TCONFIG_IPV6
53 #define IPV6_DISABLED 0
54 #define IPV6_NATIVE 1
55 #define IPV6_NATIVE_DHCP 2
56 #define IPV6_ANYCAST_6TO4 3
57 #define IPV6_6IN4 4
58 #define IPV6_MANUAL 5
59 #define IPV6_6RD 6
60 #define IPV6_6RD_DHCP 7
61 #endif
63 enum {
64 ACT_IDLE,
65 ACT_TFTP_UPGRADE_UNUSED,
66 ACT_WEB_UPGRADE,
67 ACT_WEBS_UPGRADE_UNUSED,
68 ACT_SW_RESTORE,
69 ACT_HW_RESTORE,
70 ACT_ERASE_NVRAM,
71 ACT_NVRAM_COMMIT,
72 ACT_REBOOT,
73 ACT_UNKNOWN
76 typedef struct {
77 int count;
78 struct {
79 struct in_addr addr;
80 unsigned short port;
81 } dns[6];
82 } dns_list_t;
84 typedef struct {
85 int count;
86 struct {
87 char name[IFNAMSIZ + 1];
88 char ip[sizeof("xxx.xxx.xxx.xxx") + 1];
89 } iface[2];
90 } wanface_list_t;
92 extern void chld_reap(int sig);
93 extern int get_wan_proto(void);
94 #ifdef TCONFIG_IPV6
95 extern int get_ipv6_service(void);
96 #define ipv6_enabled() (get_ipv6_service() != IPV6_DISABLED)
97 extern const char *ipv6_router_address(struct in6_addr *in6addr);
98 extern int calc_6rd_local_prefix(const struct in6_addr *prefix,
99 int prefix_len, int relay_prefix_len,
100 const struct in_addr *local_ip,
101 struct in6_addr *local_prefix, int *local_prefix_len);
102 #else
103 #define ipv6_enabled() (0)
104 #endif
105 extern int using_dhcpc(void);
106 extern void notice_set(const char *path, const char *format, ...);
107 extern int check_wanup(void);
108 extern const dns_list_t *get_dns(void);
109 extern void set_action(int a);
110 extern int check_action(void);
111 extern int wait_action_idle(int n);
112 extern int wl_client(int unit, int subunit);
113 extern const wanface_list_t *get_wanfaces(void);
114 extern const char *get_wanface(void);
115 extern const char *get_wanip(void);
116 #ifdef TCONFIG_IPV6
117 extern const char *get_wan6face(void);
118 #endif
119 extern const char *getifaddr(char *ifname, int family, int linklocal);
120 extern long get_uptime(void);
121 extern char *wl_nvname(const char *nv, int unit, int subunit);
122 extern int get_radio(int unit);
123 extern void set_radio(int on, int unit);
124 extern int nvram_get_int(const char *key);
125 // extern long nvram_xget_long(const char *name, long min, long max, long def);
126 extern int nvram_get_file(const char *key, const char *fname, int max);
127 extern int nvram_set_file(const char *key, const char *fname, int max);
128 extern int nvram_contains_word(const char *key, const char *word);
129 extern int nvram_is_empty(const char *key);
130 extern void nvram_commit_x(void);
131 extern int connect_timeout(int fd, const struct sockaddr *addr, socklen_t len, int timeout);
132 extern int mtd_getinfo(const char *mtdname, int *part, int *size);
133 extern int foreach_wif(int include_vifs, void *param,
134 int (*func)(int idx, int unit, int subunit, void *param));
136 // usb.c
137 #ifdef TCONFIG_USB
138 extern struct mntent *findmntents(char *file, int swp,
139 int (*func)(struct mntent *mnt, uint flags), uint flags);
140 extern char *find_label_or_uuid(char *dev_name, char *label, char *uuid);
141 extern void add_remove_usbhost(char *host, int add);
143 #define DEV_DISCS_ROOT "/dev/discs"
145 /* Flags used in exec_for_host calls
147 #define EFH_1ST_HOST 0x00000001 /* func is called for the 1st time for this host */
148 #define EFH_1ST_DISC 0x00000002 /* func is called for the 1st time for this disc */
149 #define EFH_HUNKNOWN 0x00000004 /* host is unknown */
150 #define EFH_USER 0x00000008 /* process is user-initiated - either via Web GUI or a script */
151 #define EFH_SHUTDN 0x00000010 /* exec_for_host is called at shutdown - system is stopping */
152 #define EFH_HP_ADD 0x00000020 /* exec_for_host is called from "add" hotplug event */
153 #define EFH_HP_REMOVE 0x00000040 /* exec_for_host is called from "remove" hotplug event */
154 #define EFH_PRINT 0x00000080 /* output partition list to the web response */
156 typedef int (*host_exec)(char *dev_name, int host_num, char *dsc_name, char *pt_name, uint flags);
157 extern int exec_for_host(int host, int obsolete, uint flags, host_exec func);
158 extern int is_no_partition(const char *discname);
159 extern int file_lock(char *tag);
160 extern void file_unlock(int lockfd);
161 #else
162 #define file_lock(args...) (-1)
163 #define file_unlock(args...) do { } while(0)
164 #endif //TCONFIG_USB
166 // id.c
167 enum {
168 MODEL_UNKNOWN,
169 MODEL_WRT54G,
170 MODEL_WRTSL54GS,
171 MODEL_WHRG54S,
172 MODEL_WHRHPG54,
173 MODEL_WR850GV1,
174 MODEL_WR850GV2,
175 MODEL_WZRG54,
176 MODEL_WL500W,
177 MODEL_WL500GP,
178 MODEL_WL500GPv2,
179 MODEL_WL500GE,
180 MODEL_WL500GD,
181 MODEL_WL520GU,
182 MODEL_DIR320,
183 MODEL_H618B,
184 MODEL_WL1600GL,
185 MODEL_WBRG54,
186 MODEL_WBR2G54,
187 MODEL_WX6615GT,
188 MODEL_WZRHPG54,
189 MODEL_WZRRSG54,
190 MODEL_WZRRSG54HP,
191 MODEL_WVRG54NF,
192 MODEL_WHR2A54G54,
193 MODEL_WHR3AG54,
194 MODEL_RT390W,
195 MODEL_RTN10,
196 MODEL_RTN12,
197 MODEL_RTN16,
198 MODEL_RTN66U,
199 MODEL_WNR3500L,
200 MODEL_WNR2000v2,
201 MODEL_F7D3301,
202 MODEL_F7D3302,
203 MODEL_F7D4301,
204 MODEL_F7D4302,
205 MODEL_F5D8235v3,
206 MODEL_WRT160Nv1,
207 MODEL_WRT160Nv3,
208 MODEL_WRT320N,
209 MODEL_WRT610Nv2,
210 MODEL_WRT310Nv1,
211 MODEL_E4200,
212 MODEL_MN700,
213 MODEL_WRH54G,
214 MODEL_WHRG125,
215 MODEL_WZRG108,
216 MODEL_WTR54GS,
217 MODEL_WR100,
218 MODEL_WLA2G54L,
219 MODEL_TM2300,
220 MODEL_WZRG300N,
221 MODEL_WRT300N,
222 MODEL_WL330GE
225 /* NOTE: Do not insert new entries in the middle of this enum,
226 * always add them to the end! The numeric Hardware ID value is
227 * stored in the configuration file, and is used to determine
228 * whether or not this config file can be restored on the router.
230 enum {
231 HW_BCM4702,
232 HW_BCM4712,
233 HW_BCM5325E,
234 HW_BCM4704_BCM5325F,
235 HW_BCM5352E,
236 HW_BCM5354G,
237 HW_BCM4712_BCM5325E,
238 HW_BCM4704_BCM5325F_EWC,
239 HW_BCM4705L_BCM5325E_EWC,
240 HW_BCM5350,
241 HW_BCM5356,
242 HW_BCM4716,
243 HW_BCM4718,
244 HW_BCM4717,
245 HW_BCM5365,
246 HW_BCM4785,
247 HW_BCM4706,
248 HW_UNKNOWN
251 #define SUP_SES (1 << 0)
252 #define SUP_BRAU (1 << 1)
253 #define SUP_AOSS_LED (1 << 2)
254 #define SUP_WHAM_LED (1 << 3)
255 #define SUP_HPAMP (1 << 4)
256 #define SUP_NONVE (1 << 5)
257 #define SUP_80211N (1 << 6)
258 #define SUP_1000ET (1 << 7)
260 extern int check_hw_type(void);
261 // extern int get_hardware(void) __attribute__ ((weak, alias ("check_hw_type")));
262 extern int get_model(void);
263 extern int supports(unsigned long attr);
266 // process.c
267 extern char *psname(int pid, char *buffer, int maxlen);
268 extern int pidof(const char *name);
269 extern int killall(const char *name, int sig);
270 extern int ppid(int pid);
273 // files.c
274 #define FW_CREATE 0
275 #define FW_APPEND 1
276 #define FW_NEWLINE 2
278 extern unsigned long f_size(const char *path);
279 extern int f_exists(const char *file);
280 extern int f_read(const char *file, void *buffer, int max); // returns bytes read
281 extern int f_write(const char *file, const void *buffer, int len, unsigned flags, unsigned cmode); //
282 extern int f_read_string(const char *file, char *buffer, int max); // returns bytes read, not including term; max includes term
283 extern int f_write_string(const char *file, const char *buffer, unsigned flags, unsigned cmode); //
284 extern int f_read_alloc(const char *path, char **buffer, int max);
285 extern int f_read_alloc_string(const char *path, char **buffer, int max);
286 extern int f_wait_exists(const char *name, int max);
287 extern int f_wait_notexists(const char *name, int max);
290 // led.c
291 #define LED_WLAN 0
292 #define LED_DIAG 1
293 #define LED_WHITE 2
294 #define LED_AMBER 3
295 #define LED_DMZ 4
296 #define LED_AOSS 5
297 #define LED_BRIDGE 6
298 #define LED_USB 7
299 #define LED_MYSTERY LED_USB // (unmarked LED between wireless and bridge on WHR-G54S)
300 #define LED_COUNT 8
302 #define LED_OFF 0
303 #define LED_ON 1
304 #define LED_BLINK 2
305 #define LED_PROBE 3
307 extern const char *led_names[];
309 extern int gpio_open(uint32_t mask);
310 extern void gpio_write(uint32_t bit, int en);
311 extern uint32_t gpio_read(void);
312 extern uint32_t _gpio_read(int f);
313 extern int nvget_gpio(const char *name, int *gpio, int *inv);
314 extern int do_led(int which, int mode);
315 static inline int led(int which, int mode)
317 return (do_led(which, mode) != 255);
321 // base64.c
322 extern int base64_encode(unsigned char *in, char *out, int inlen); // returns amount of out buffer used
323 extern int base64_decode(const char *in, unsigned char *out, int inlen); // returns amount of out buffer used
324 extern int base64_encoded_len(int len);
325 extern int base64_decoded_len(int len); // maximum possible, not actual
328 // strings.c
329 extern const char *find_word(const char *buffer, const char *word);
330 extern int remove_word(char *buffer, const char *word);
332 #endif