4 #include <tomato_profile.h>
5 #include <tomato_config.h>
7 #include <netinet/in.h>
13 #include <mntent.h> // !!TB
16 #define Y2K 946684800UL // seconds since 1970
18 #define ASIZE(array) (sizeof(array) / sizeof(array[0]))
21 #define MTD_DEV(arg) "/dev/mtd"#arg
22 #define MTD_BLKDEV(arg) "/dev/mtdblock"#arg
23 #define DEV_GPIO(arg) "/dev/gpio"#arg
25 #define MTD_DEV(arg) "/dev/mtd/"#arg
26 #define MTD_BLKDEV(arg) "/dev/mtdblock/"#arg
27 #define DEV_GPIO(arg) "/dev/gpio/"#arg
31 extern const char *tomato_version
;
32 extern const char *tomato_buildtime
;
33 extern const char *tomato_shortver
;
37 #define _dprintf cprintf
39 #define _dprintf(args...) do { } while(0)
44 #define WP_DISABLED 0 // order must be synced with def in misc.c
53 #define IPV6_DISABLED 0
55 #define IPV6_NATIVE_DHCP 2
56 #define IPV6_ANYCAST_6TO4 3
60 #define IPV6_6RD_DHCP 7
65 ACT_TFTP_UPGRADE_UNUSED
,
67 ACT_WEBS_UPGRADE_UNUSED
,
87 char name
[IFNAMSIZ
+ 1];
88 char ip
[sizeof("xxx.xxx.xxx.xxx") + 1];
92 extern void chld_reap(int sig
);
93 extern int get_wan_proto(void);
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
);
103 #define ipv6_enabled() (0)
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);
117 extern const char *get_wan6face(void);
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
));
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
);
162 #define file_lock(args...) (-1)
163 #define file_unlock(args...) do { } while(0)
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.
238 HW_BCM4704_BCM5325F_EWC
,
239 HW_BCM4705L_BCM5325E_EWC
,
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
);
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
);
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
);
299 #define LED_MYSTERY LED_USB // (unmarked LED between wireless and bridge on WHR-G54S)
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);
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
329 extern const char *find_word(const char *buffer
, const char *word
);
330 extern int remove_word(char *buffer
, const char *word
);