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_flush(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_flush(int);
71 * Do some kernel-style types to make
72 * definitions shorter.
74 typedef unsigned int 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 UNKNOWN_5 = 5, // Chris says these are
166 UNKNOWN_6 = 6, // checksums
169 UNKNOWN_13 = 13, // Returns an ASCII SSID. Last connected or
170 // current WiFi network, maybe?
173 UNKNOWN_ff = 0xff, // The D90 does this, and it looks to
174 // return a 1-byte response length
175 // followed by a number of 8-byte responses
176 // But I've only ever seen a single response
177 // [000]: 01 04 1d 00 18 56 aa d5 42 00 00 00 00 00 00 00
181 ///media/NIKON D90/EYEFI/REQM
182 //00000000 4f 0a 01 00 00 00 00 00 00 00 00 00 00 00 00 00 |O...............|
183 //00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
184 // that happens 3 seconds after the card goes into the D90
186 struct card_info_req {
189 } __attribute__((packed));
191 struct card_info_rsp_key {
192 struct pascal_string key;
195 struct card_firmware_info {
196 struct pascal_string info;
203 } __attribute__((packed));
205 struct card_info_api_url {
206 struct pascal_string key;
209 struct card_info_log_len {
212 } __attribute__((packed));
214 struct byte_response {
218 struct var_byte_response {
220 struct byte_response responses[0];
230 enum net_password_type {
232 NET_PASSWORD_RAW, /* raw hex bytes */
237 char essid[ESSID_LEN];
238 signed char strength;
240 } __attribute__((packed));
242 struct scanned_net_list {
244 struct scanned_net nets[100];
245 } __attribute__((packed));
247 struct configured_net {
248 char essid[ESSID_LEN];
249 } __attribute__((packed));
251 struct configured_net_list {
253 struct configured_net nets[100];
254 } __attribute__((packed));
256 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
258 #define WPA_KEY_BYTES 32
260 u8 key[WPA_KEY_BYTES];
261 } __attribute((packed));
263 #define WEP_40_KEY_BYTES 5
264 #define WEP_KEY_BYTES 13
266 u8 key[WEP_KEY_BYTES];
267 } __attribute((packed));
276 } __attribute((packed));
282 char essid[ESSID_LEN];
283 struct network_key key;
284 } __attribute((packed));
286 struct noarg_request {
293 struct fetch_log_cmd {
296 } __attribute__((packed));
299 * When you ask for the log at offset 0x0, you
300 * get back 8 bytes of offsets into the rest of
303 struct first_log_response {
306 u8 data[EYEFI_BUF_SIZE-8];
307 } __attribute__((packed));
309 struct rest_log_response {
310 u8 data[EYEFI_BUF_SIZE];
311 } __attribute__((packed));
314 * Functions that are exported from eyefi-config.c
316 u32 fetch_log_length(void);
317 int card_info_cmd(enum card_info_subcommand cmd);
318 void *eyefi_response(void);
319 struct card_info_rsp_key *fetch_card_key(void);
320 struct scanned_net_list *scan_nets(void);
321 const char *net_type_name(u8 type);
322 struct configured_net_list *fetch_configured_nets(void);
323 int issue_noarg_command(u8 cmd);
324 char *net_test_state_name(u8 state);
325 int network_action(char cmd, char *essid, char *wpa_ascii);
326 char *locate_eyefi_mount(void);
327 int get_log_into(u8 *resbuf);
328 void reboot_card(void);
329 void init_card(void);
330 void add_network(char *essid, char *ascii_password);
331 void remove_network(char *essid);
332 struct card_firmware_info *fetch_card_firmware_info(void);
334 * Only used by the unix variants
342 char *eyefi_file_on(enum eyefi_file file, char *mnt);
344 #endif // _EYEFI_CONFIG_H