CHDK_DE Vorschauversion  Trunk Rev. 5272
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
eyefi.c-Dateireferenz
#include <gui.h>
#include <string.h>
#include "gui_lang.h"
#include "gui_mbox.h"
#include "gui_tbox.h"
#include "gui_mpopup.h"
#include "gui_menu.h"
#include "eyefi.h"
#include "simple_module.h"
+ Include-Abhängigkeitsdiagramm für eyefi.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  network_key
 
struct  __attribute__
 
struct  __attribute__
 
struct  __attribute__
 
struct  __attribute__
 
struct  __attribute__
 
struct  __attribute__
 
struct  __attribute__
 

Makrodefinitionen

#define EINVAL   1000
 
#define EYEFI_BUF_SIZE   16384
 
#define ESSID_LEN   32
 
#define WPA_KEY_BYTES   32
 
#define WEP_KEY_BYTES   13
 
#define WEP_40_KEY_BYTES   5
 
#define eyefi_sendCommand(cmd)   eyefi_sendCommandParam(cmd, NULL)
 
#define eyefi_getAvailableNetworks()   eyefi_sendCommand('g')
 
#define eyefi_getConfiguredNetworks()   eyefi_sendCommand('l')
 
#define eyefi_getNetworkStatus()   eyefi_sendCommand('s')
 
#define MAX_NETWORK   9
 
#define PWD_LEN   32
 

Aufzählungen

enum  test_status {
  EYEFI_NOT_SCANNING, EYEFI_LOCATING_NETWORK, EYEFI_VERIFYING_NETWORK_KEY, EYEFI_WAITING_FOR_DHCP,
  EYEFI_TESTING_CONN_TO_SERVER, EYEFI_SUCCESS
}
 
enum  card_info_subcommand {
  EYEFI_MAC_ADDRESS = 1, EYEFI_FIRMWARE_INFO = 2, EYEFI_CARD_KEY = 3, EYEFI_API_URL = 4,
  EYEFI_UNKNOWN_5 = 5, EYEFI_UNKNOWN_6 = 6, EYEFI_LOG_LEN = 7, EYEFI_WLAN_DISABLE = 10,
  EYEFI_UPLOAD_PENDING = 11, EYEFI_HOTSPOT_ENABLE = 12, EYEFI_CONNECTED_TO = 13, EYEFI_UPLOAD_STATUS = 14,
  EYEFI_UNKNOWN_15 = 15, EYEFI_TRANSFER_MODE = 17, EYEFI_ENDLESS = 27, EYEFI_DIRECT_WAIT_FOR_CONNECTION = 0x24,
  EYEFI_DIRECT_WAIT_AFTER_TRANSFER = 0x25, EYEFI_UNKNOWN_ff = 0xff
}
 

Funktionen

struct network_key __attribute__ ((packed))
 
static void clear_eyefi_buf ()
 
static u8 atoh (char c)
 
static u8convert_ascii_to_hex (char *ascii)
 
static int hex_only (char *str)
 
static int make_network_key (struct network_key *key, char *essid, char *pass)
 
static char * eyefi_filename (const char *nm)
 
static int eyefi_writeFile (const char *filename)
 
static int eyefi_readFile (const char *filename)
 
static int eyefi_sendCommandParam (unsigned char cmd, eyefi_param *param)
 
int eyefi_networkAction (unsigned char cmd, char *SSID, char *pwd)
 
int eyefi_deleteNetwork (char *SSID)
 
int eyefi_testNetwork (char *SSID, char *pwd)
 
int eyefi_addNetwork (char *SSID, char *pwd)
 
int eyefi_enableWlan (int enable)
 
char * eyefi_statusName (int n)
 
static void eyefi_exit (unsigned int button)
 
static void eyefi_wlan_state (int on_off)
 
static void confirm_delete_network_cb (unsigned int btn)
 
static void select_configured_network_cb (unsigned nSelected)
 
static void eyefi_configured_networks ()
 
static void confirm_add_network_cb (unsigned int btn)
 
static void password_cb (const char *str)
 
static void select_available_network_cb (unsigned nSelected)
 
static void eyefi_available_networks ()
 
static void eyefi_wlan_off ()
 
static void eyefi_wlan_on ()
 
int _module_can_unload ()
 
int _run ()
 
int _module_exit_alt ()
 

Variablen

typedef __attribute__
 *-------------------------------------------------------------------— Mehr ...
 
u8 len
 
u8 key [WPA_KEY_BYTES]
 
unsigned char subcommand
 
unsigned char bytes
 
unsigned char args [32]
 
static int running = 0
 
static _eyefi_interface eyefi_buf
 
static struct mpopup_item popup_eyefi [MAX_NETWORK+1]
 
static char eyefi_selectedNetwork [ESSID_LEN+1]
 
static char eyefi_password [PWD_LEN+1]
 
static CMenuItem eyefi_submenu_items []
 
static CMenu eyefi_submenu = {0x21,LANG_MENU_EYEFI_TITLE, eyefi_submenu_items }
 
libsimple_sym _libeyefi
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define EINVAL   1000

Definiert in Zeile 19 der Datei eyefi.c.

#define ESSID_LEN   32

Definiert in Zeile 21 der Datei eyefi.c.

#define EYEFI_BUF_SIZE   16384

Definiert in Zeile 20 der Datei eyefi.c.

#define eyefi_getAvailableNetworks ( )    eyefi_sendCommand('g')

Definiert in Zeile 318 der Datei eyefi.c.

#define eyefi_getConfiguredNetworks ( )    eyefi_sendCommand('l')

Definiert in Zeile 319 der Datei eyefi.c.

#define eyefi_getNetworkStatus ( )    eyefi_sendCommand('s')

Definiert in Zeile 320 der Datei eyefi.c.

#define eyefi_sendCommand (   cmd)    eyefi_sendCommandParam(cmd, NULL)

Definiert in Zeile 317 der Datei eyefi.c.

#define MAX_NETWORK   9

Definiert in Zeile 394 der Datei eyefi.c.

#define PWD_LEN   32

Definiert in Zeile 395 der Datei eyefi.c.

#define WEP_40_KEY_BYTES   5

Definiert in Zeile 26 der Datei eyefi.c.

#define WEP_KEY_BYTES   13

Definiert in Zeile 25 der Datei eyefi.c.

#define WPA_KEY_BYTES   32

Definiert in Zeile 24 der Datei eyefi.c.

Dokumentation der Aufzählungstypen

Aufzählungswerte
EYEFI_MAC_ADDRESS 
EYEFI_FIRMWARE_INFO 
EYEFI_CARD_KEY 
EYEFI_API_URL 
EYEFI_UNKNOWN_5 
EYEFI_UNKNOWN_6 
EYEFI_LOG_LEN 
EYEFI_WLAN_DISABLE 
EYEFI_UPLOAD_PENDING 
EYEFI_HOTSPOT_ENABLE 
EYEFI_CONNECTED_TO 
EYEFI_UPLOAD_STATUS 
EYEFI_UNKNOWN_15 
EYEFI_TRANSFER_MODE 
EYEFI_ENDLESS 
EYEFI_DIRECT_WAIT_FOR_CONNECTION 
EYEFI_DIRECT_WAIT_AFTER_TRANSFER 
EYEFI_UNKNOWN_ff 

Definiert in Zeile 42 der Datei eyefi.c.

43 {
46  EYEFI_CARD_KEY = 3,
47  EYEFI_API_URL = 4,
48  EYEFI_UNKNOWN_5 = 5, // Chris says these are
49  EYEFI_UNKNOWN_6 = 6, // checksums
50  EYEFI_LOG_LEN = 7,
51  EYEFI_WLAN_DISABLE = 10, // 1=disable 0=enable, write is 1 byte, read is var_byte
52  EYEFI_UPLOAD_PENDING= 11, // {0x1, STATE}
53  EYEFI_HOTSPOT_ENABLE= 12, // {0x1, STATE}
54  EYEFI_CONNECTED_TO = 13, // Currently connected Wifi network
55  EYEFI_UPLOAD_STATUS = 14, // current uploading file info
56  EYEFI_UNKNOWN_15 = 15, // always returns {0x01, 0x1d} as far as I've seen
58  EYEFI_ENDLESS = 27, // 0x1b
59  EYEFI_DIRECT_WAIT_FOR_CONNECTION = 0x24, // 0 == "direct mode off"
60  EYEFI_DIRECT_WAIT_AFTER_TRANSFER = 0x25, // set to 60 when direct mode off
61  EYEFI_UNKNOWN_ff = 0xff, // The D90 does this, and it looks to
62  // return a 1-byte response length
63  // followed by a number of 8-byte responses
64  // But I've only ever seen a single response
65  // [000]: 01 04 1d 00 18 56 aa d5 42 00 00 00 00 00 00 00
66  // It could be a consolidates info command like "info for
67  // everything" so the camera makes fewer calls.
68 };
Aufzählungswerte
EYEFI_NOT_SCANNING 
EYEFI_LOCATING_NETWORK 
EYEFI_VERIFYING_NETWORK_KEY 
EYEFI_WAITING_FOR_DHCP 
EYEFI_TESTING_CONN_TO_SERVER 
EYEFI_SUCCESS 

Definiert in Zeile 29 der Datei eyefi.c.

Dokumentation der Funktionen

struct network_key __attribute__ ( (packed)  )
int _module_can_unload ( )

Definiert in Zeile 634 der Datei eyefi.c.

635 {
636  return (running == 0) || (get_curr_menu() != &eyefi_submenu);
637 }
int _module_exit_alt ( )

Definiert in Zeile 646 der Datei eyefi.c.

647 {
648  running = 0;
649  return 0;
650 }
int _run ( )

Definiert in Zeile 639 der Datei eyefi.c.

640 {
641  running = 1;
643  return 0;
644 }
static u8 atoh ( char  c)
static

Definiert in Zeile 155 der Datei eyefi.c.

156 {
157  char lc = tolower(c);
158  if ((c >= '0') && (c <= '9'))
159  return c - '0';
160  else if ((lc >= 'a') && (lc <= 'z'))
161  return (lc - 'a') + 10;
162  return 0;
163 }
static void clear_eyefi_buf ( )
static

Definiert in Zeile 150 der Datei eyefi.c.

151 {
153 }
static void confirm_add_network_cb ( unsigned int  btn)
static

Definiert in Zeile 490 der Datei eyefi.c.

491 {
492  int n,i;
493  char s[80];
494 
495  if (btn==MBOX_BTN_YES)
496  {
498  gui_browser_progress_show("testing network",5);
499  for (i=0; i<50; i++)
500  {
501  msleep(10);
503  if (eyefi_buf.status == 0)
504  {
506  return;
507  }
508  if (eyefi_buf.status <= EYEFI_SUCCESS)
509  {
511  if (eyefi_buf.status == EYEFI_SUCCESS)
512  break;
513  }
514  else
515  gui_browser_progress_show("????",50);
516  }
517 
518  if (eyefi_buf.status != EYEFI_SUCCESS)
519  {
521  return;
522  }
523  }
524 
525  gui_browser_progress_show("adding network", 95);
527  if (n > 0)
529  else
531 }
static void confirm_delete_network_cb ( unsigned int  btn)
static

Definiert in Zeile 420 der Datei eyefi.c.

static u8* convert_ascii_to_hex ( char *  ascii)
static

Definiert in Zeile 171 der Datei eyefi.c.

172 {
173  int i;
174  static u8 hex[32];
175  int len = strlen(ascii);
176 
177  memset(hex, 0, 32);
178 
179  for (i = 0; i < len; i += 2)
180  {
181  u8 high = atoh(ascii[i]);
182  u8 low = atoh(ascii[i+1]);
183  hex[i/2] = (high<<4) | low;
184  }
185 
186  return hex;
187 }
int eyefi_addNetwork ( char *  SSID,
char *  pwd 
)

Definiert in Zeile 346 der Datei eyefi.c.

347 {
348  return eyefi_networkAction('a', SSID, pwd);
349 }
static void eyefi_available_networks ( )
static

Definiert in Zeile 574 der Datei eyefi.c.

575 {
576  unsigned flag=1,flags=0;
577  int i,n;
578 
579  running = 1;
580 
581  if (eyefi_getAvailableNetworks() <= 0)
582  {
584  }
585  else
586  {
588  n = eyefi_buf.a.count;
589 
590  if (n == 0)
591  {
593  }
594  else
595  {
596  for (i=0; i<n && i<MAX_NETWORK; i++)
597  {
598  popup_eyefi[i].text = (int)&(eyefi_buf.a.nets[i].essid);
599  popup_eyefi[i].flag = flag;
600  flags |= flag;
601  flag <<= 1;
602  }
603  popup_eyefi[i].text = (int)"Cancel";
605 
607  }
608  }
609 }
static void eyefi_configured_networks ( )
static

Definiert in Zeile 461 der Datei eyefi.c.

462 {
463  unsigned flag=1,flags=0;
464  int i,n;
465 
466  running = 1;
467 
468  if (eyefi_getConfiguredNetworks() <= 0)
469  {
471  }
472  else
473  {
475  n = eyefi_buf.c.count;
476  for (i=0; i<n && i<MAX_NETWORK; i++)
477  {
478  popup_eyefi[i].text = (int)(eyefi_buf.c.nets[i].essid);
479  popup_eyefi[i].flag = flag;
480  flags |= flag;
481  flag <<= 1;
482  }
483  popup_eyefi[i].text = (int)"Cancel";
485 
487  }
488 }
int eyefi_deleteNetwork ( char *  SSID)

Definiert in Zeile 336 der Datei eyefi.c.

337 {
338  return eyefi_networkAction('d', SSID, NULL);
339 }
int eyefi_enableWlan ( int  enable)

Definiert in Zeile 352 der Datei eyefi.c.

353 {
354  eyefi_param param;
355  memset(&param, 0, sizeof(eyefi_param));
356  param.config.subcommand = EYEFI_WLAN_DISABLE;
357  param.config.bytes = 1;
358  param.config.args[0] = (unsigned char)enable;
359  return eyefi_sendCommandParam('O', &param);
360 }
static void eyefi_exit ( unsigned int  button)
static

Definiert in Zeile 402 der Datei eyefi.c.

403 {
404  running = 0;
406 }
static char* eyefi_filename ( const char *  nm)
static

Definiert in Zeile 235 der Datei eyefi.c.

236 {
237  static char path[16];
238 
239  strcpy(path, "A/EyeFi/");
240  strcat(path, nm);
241 
242  return path;
243 }
int eyefi_networkAction ( unsigned char  cmd,
char *  SSID,
char *  pwd 
)

Definiert in Zeile 323 der Datei eyefi.c.

324 {
325  eyefi_param param;
326  memset(&param, 0, sizeof(eyefi_param));
327  param.network.length = (unsigned char)strlen(SSID);
328  strcpy(param.network.SSID, SSID);
329  if (pwd)
330  {
331  make_network_key(&param.network.key, SSID, pwd);
332  }
333  return eyefi_sendCommandParam(cmd, &param);
334 }
static int eyefi_readFile ( const char *  filename)
static

Definiert in Zeile 262 der Datei eyefi.c.

263 {
264  clear_eyefi_buf();
265 
266  int fd = open(eyefi_filename(filename), O_RDONLY, 0777);
267 
268  if (fd < 0)
269  return 0;
270 
271  int bytesRead = read(fd, eyefi_buf.buf, EYEFI_BUF_SIZE);
272  close(fd);
273 
274  return bytesRead == EYEFI_BUF_SIZE;
275 }
static int eyefi_sendCommandParam ( unsigned char  cmd,
eyefi_param *  param 
)
static

Definiert in Zeile 284 der Datei eyefi.c.

285 {
286  int i;
287 
288  if (!eyefi_readFile("RSPC")) return 0;
289  unsigned int cur_seq = eyefi_buf.seq;
290 
291  clear_eyefi_buf();
292  eyefi_buf.ec.cmd = cmd;
293 
294  if (param)
295  memcpy(&eyefi_buf.ec.param, param, sizeof(eyefi_param));
296 
297  if (!eyefi_writeFile("REQM")) return -1;
298 
299  clear_eyefi_buf();
300  eyefi_buf.seq = ++cur_seq;
301  if (!eyefi_writeFile("REQC")) return -2;
302 
303  for (i=0; i<20; i++)
304  {
305  if (!eyefi_readFile("RSPC")) return -3;
306  if (eyefi_buf.seq == cur_seq)
307  {
308  if (!eyefi_readFile("RSPM")) return -5;
309  return 1;
310  }
311  msleep(250);
312  }
313 
314  return -4;
315 }
char* eyefi_statusName ( int  n)

Definiert in Zeile 373 der Datei eyefi.c.

374 {
375  static char *eyefi_status[] =
376  {
377  "not scanning",
378  "locating network",
379  "verifying network_key",
380  "waiting for DHCP",
381  "testing conn. to server",
382  "success"
383  };
384 
385  if (n<0 || n>=sizeof(eyefi_status)/sizeof(*eyefi_status))
386  return "?";
387 
388  return eyefi_status[n];
389 }
int eyefi_testNetwork ( char *  SSID,
char *  pwd 
)

Definiert in Zeile 341 der Datei eyefi.c.

342 {
343  return eyefi_networkAction('t', SSID, pwd);
344 }
static void eyefi_wlan_off ( )
static

Definiert in Zeile 612 der Datei eyefi.c.

613 {
614  eyefi_wlan_state(0);
615 }
static void eyefi_wlan_on ( )
static

Definiert in Zeile 617 der Datei eyefi.c.

618 {
619  eyefi_wlan_state(1);
620 }
static void eyefi_wlan_state ( int  on_off)
static

Definiert in Zeile 408 der Datei eyefi.c.

static int eyefi_writeFile ( const char *  filename)
static

Definiert in Zeile 247 der Datei eyefi.c.

248 {
249  int fd = open(eyefi_filename(filename), O_RDWR|O_CREAT, 0600);
250 
251  if (fd < 0)
252  return 0;
253 
254  int bytesWritten = write(fd, eyefi_buf.buf, EYEFI_BUF_SIZE);
255  close(fd);
256 
257  return bytesWritten == EYEFI_BUF_SIZE;
258 }
static int hex_only ( char *  str)
static

Definiert in Zeile 189 der Datei eyefi.c.

190 {
191  int i;
192 
193  for (i = 0; i < strlen(str); i++) {
194  if (((str[i] >= 'a') && str[i] <= 'f') ||
195  ((str[i] >= 'A') && str[i] <= 'F') ||
196  ((str[i] >= '0') && str[i] <= '9')) {
197  continue;
198  }
199  return 0;
200  }
201  return 1;
202 }
static int make_network_key ( struct network_key key,
char *  essid,
char *  pass 
)
static

Definiert in Zeile 206 der Datei eyefi.c.

207 {
208  u8 *hex_pass;
209  int pass_len = strlen(pass);
210  memset(key, 0, sizeof(*key));
211 
212  switch (pass_len) {
213  case WPA_KEY_BYTES*2:
214  case WEP_KEY_BYTES*2:
215  case WEP_40_KEY_BYTES*2:
216  if (hex_only(pass))
217  {
218  hex_pass = convert_ascii_to_hex(pass);
219  if (!hex_pass)
220  return -EINVAL;
221  key->len = pass_len/2;
222  memcpy(&key->key[0], hex_pass, key->len);
223  break;
224  }
225  // Fall through to default case
226  default:
227  key->len = WPA_KEY_BYTES;
228  pbkdf2_sha1(pass, essid, strlen(essid), 4096, &key->key[0], WPA_KEY_BYTES);
229  break;
230  }
231  return 0;
232 }
static void password_cb ( const char *  str)
static

Definiert in Zeile 533 der Datei eyefi.c.

534 {
535  if (str == NULL)
536  {
537  eyefi_exit(0);
538  }
539  else
540  {
543  }
544 }
static void select_available_network_cb ( unsigned  nSelected)
static

Definiert in Zeile 546 der Datei eyefi.c.

547 {
548  unsigned flag=1;
549  int i,n;
550 
551  if (nSelected == MPOPUP_CANCEL)
552  {
553  eyefi_exit(0);
554  return;
555  }
556 
557  n = eyefi_buf.a.count;
558  for (i=0; i<n && i<MAX_NETWORK; i++)
559  {
560  if (nSelected == flag) break;
561  flag <<= 1;
562  }
563 
564  if (nSelected != flag)
565  {
567  return;
568  }
569 
570  strcpy(eyefi_selectedNetwork,eyefi_buf.a.nets[i].essid);
572 }
static void select_configured_network_cb ( unsigned  nSelected)
static

Definiert in Zeile 430 der Datei eyefi.c.

431 {
432  unsigned flag=1;
433  int i, n;
434 
435  if (nSelected == MPOPUP_CANCEL)
436  {
437  eyefi_exit(0);
438  return;
439  }
440 
441  n = eyefi_buf.c.count;
442  for (i=0; i<n && i<MAX_NETWORK; i++)
443  {
444  if (nSelected == flag) break;
445  flag <<= 1;
446  }
447 
448  if (nSelected != flag)
449  {
451  return;
452  }
453 
454  strcpy(eyefi_selectedNetwork, eyefi_buf.c.nets[i].essid);
455 
456  static char s[80];
457  sprintf(s,"Delete \"%s\"?",eyefi_selectedNetwork);
459 }

Variablen-Dokumentation

*-------------------------------------------------------------------—

!!

Definiert in Zeile 228 der Datei cache.c.

228  {
229  asm volatile (
230  "MOV r1, #0\n"
231  "MCR p15, 0, r1,c7,c5\n"
232  "BX LR\n"
233  );
234 }
libsimple_sym _libeyefi
Initialisierung:

Definiert in Zeile 656 der Datei eyefi.c.

unsigned char args[32]

Definiert in Zeile 107 der Datei eyefi.c.

unsigned char bytes

Definiert in Zeile 106 der Datei eyefi.c.

_eyefi_interface eyefi_buf
static

Definiert in Zeile 148 der Datei eyefi.c.

char eyefi_password[PWD_LEN+1]
static

Definiert in Zeile 399 der Datei eyefi.c.

char eyefi_selectedNetwork[ESSID_LEN+1]
static

Definiert in Zeile 398 der Datei eyefi.c.

CMenu eyefi_submenu = {0x21,LANG_MENU_EYEFI_TITLE, eyefi_submenu_items }
static

Definiert in Zeile 631 der Datei eyefi.c.

Definiert in Zeile 20 der Datei eyefi.c.

u8 len

Definiert in Zeile 19 der Datei eyefi.c.

struct mpopup_item popup_eyefi[MAX_NETWORK+1]
static

Definiert in Zeile 397 der Datei eyefi.c.

int running = 0
static

Definiert in Zeile 147 der Datei eyefi.c.

unsigned char subcommand

Definiert in Zeile 105 der Datei eyefi.c.