1 #ifndef _EYEFI_CONFIG_H
2 #define _EYEFI_CONFIG_H
6 #if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
7 #define __LITTLE_ENDIAN LITTLE_ENDIAN
10 #if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
11 #define __BIG_ENDIAN BIG_ENDIAN
14 #if !defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN)
19 extern int eyefi_debug_level;
23 #define CONFIG_EYEFI_STANDALONE 1
24 #define printf(...) do{}while(0)
25 #define putchar(...) do{}while(0)
26 #define puts(...) do{}while(0)
27 #define exit(i) return
28 #define perror(i) do{}while(0)
29 #define system(i) do{}while(0)
30 #define fd_dont_cache(fd) (0)
31 #define assert(x) do{}while(0)
32 #define output_flush() do{}while(0)
35 #define CONFIG_EYEFI_WITH_OS 1
42 #include <sys/types.h>
48 #define PATHNAME_MAX 4096
50 #define output_flush() fflush(NULL)
52 #define debug_printf(level, args...) do { \
53 if ((level) <= eyefi_debug_level) \
54 fprintf(stderr, ## args); \
60 * These are defined in both eyefi-unix.c and eyefi-chdk.c
62 extern void open_error(char *file, int err);
63 extern int eyefi_printf(const char *fmt, ...);
66 * These have to be created by the unix variants
68 extern int fd_dont_cache(int);
71 * Do some kernel-style types to make
72 * definitions shorter.
74 typedef unsigned long u32;
75 typedef unsigned char u8;
77 #define os_memset memset
78 #define os_memcpy memcpy
79 #define os_strlen strlen
80 #define os_strcpy strcpy
82 #define SHA1_MAC_LEN 20
83 #define MD5_MAC_LEN 16
84 void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
85 void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
86 void hmac_md5_vector(const u8 *key, size_t key_len, size_t num_elem,
87 const u8 *addr[], const size_t *len, u8 *mac);
88 void hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
90 void pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
91 int iterations, u8 *buf, size_t buflen);
93 static inline u32 swap_bytes(u32 src)
96 dest |= (src & 0xff000000) >> 24;
97 dest |= (src & 0x00ff0000) >> 8;
98 dest |= (src & 0x0000ff00) << 8;
99 dest |= (src & 0x000000ff) << 24;
103 #ifdef __LITTLE_ENDIAN
104 #define le_to_host32(n) (n)
105 #define be_to_host32(n) swap_bytes(n)
106 #define host_to_be32(n) swap_bytes(n)
107 #else // __BIG_ENDIAN
108 #define le_to_host32(n) swap_bytes(n)
109 #define be_to_host32(n) (n)
110 #define host_to_be32(n) (n)
114 * Just a few functions so that I can't easily forget about
119 } __attribute__((packed));
120 typedef struct __be32 be32;
123 * These two obviously need to get fixed for
124 * big endian machines.
126 static inline u32 be32_to_u32(be32 src)
128 return swap_bytes(src.val);
130 static inline be32 u32_to_be32(u32 src)
133 ret.val = swap_bytes(src);
138 * Eye-Fi Card data structures
141 struct card_seq_num {
143 } __attribute__((packed));
145 #define EYEFI_BUF_SIZE 16384
148 * Most of the eyefi strings are pascal-style with
149 * a length byte preceeding content. (Did pascal
150 * have just a byte for length or more??)
152 struct pascal_string {
155 } __attribute__((packed));
158 * The 'o' command has several sub-commands:
160 enum card_info_subcommand {
165 UNKNOWN1 = 5, // Chris says these are
166 UNKNOWN2 = 6, // checksums
170 struct card_info_req {
173 } __attribute__((packed));
175 struct card_info_rsp_key {
176 struct pascal_string key;
179 struct card_firmware_info {
180 struct pascal_string info;
187 } __attribute__((packed));
189 struct card_info_api_url {
190 struct pascal_string key;
193 struct card_info_log_len {
196 } __attribute__((packed));
198 struct byte_response {
209 enum net_password_type {
211 NET_PASSWORD_RAW, /* raw hex bytes */
216 char essid[ESSID_LEN];
217 signed char strength;
219 } __attribute__((packed));
221 struct scanned_net_list {
223 struct scanned_net nets[100];
224 } __attribute__((packed));
226 struct configured_net {
227 char essid[ESSID_LEN];
228 } __attribute__((packed));
230 struct configured_net_list {
232 struct configured_net nets[100];
233 } __attribute__((packed));
235 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
237 #define WPA_KEY_BYTES 32
239 u8 key[WPA_KEY_BYTES];
240 } __attribute((packed));
242 #define WEP_KEY_BYTES 13
244 u8 key[WEP_KEY_BYTES];
245 } __attribute((packed));
253 } __attribute((packed));
259 char essid[ESSID_LEN];
260 struct network_key key;
261 } __attribute((packed));
263 struct noarg_request {
270 struct fetch_log_cmd {
273 } __attribute__((packed));
276 * When you ask for the log at offset 0x0, you
277 * get back 8 bytes of offsets into the rest of
280 struct first_log_response {
283 u8 data[EYEFI_BUF_SIZE-8];
284 } __attribute__((packed));
286 struct rest_log_response {
287 u8 data[EYEFI_BUF_SIZE];
288 } __attribute__((packed));
291 * Functions that are exported from eyefi-config.c
293 u32 fetch_log_length(void);
294 int card_info_cmd(enum card_info_subcommand cmd);
295 void *eyefi_response(void);
296 struct card_info_rsp_key *fetch_card_key(void);
297 struct scanned_net_list *scan_nets(void);
298 const char *net_type_name(u8 type);
299 struct configured_net_list *fetch_configured_nets(void);
300 int issue_noarg_command(u8 cmd);
301 char *net_test_state_name(u8 state);
302 int network_action(char cmd, char *essid, char *wpa_ascii);
303 char *locate_eyefi_mount(void);
304 int get_log_into(u8 *resbuf);
305 void reboot_card(void);
306 void init_card(void);
307 void add_network(char *essid, char *ascii_password);
308 void remove_network(char *essid);
309 struct card_firmware_info *fetch_card_firmware_info(void);
311 * Only used by the unix variants
319 char *eyefi_file_on(enum eyefi_file file, char *mnt);
321 #endif // _EYEFI_CONFIG_H