CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
eyefi.c-Dateireferenz
#include "gui.h"
#include "string.h"
#include "ctype.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 (__attribute__((unused)) 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 20 der Datei eyefi.c.

#define ESSID_LEN   32

Definiert in Zeile 22 der Datei eyefi.c.

#define EYEFI_BUF_SIZE   16384

Definiert in Zeile 21 der Datei eyefi.c.

#define eyefi_getAvailableNetworks ( )    eyefi_sendCommand('g')

Definiert in Zeile 319 der Datei eyefi.c.

#define eyefi_getConfiguredNetworks ( )    eyefi_sendCommand('l')

Definiert in Zeile 320 der Datei eyefi.c.

#define eyefi_getNetworkStatus ( )    eyefi_sendCommand('s')

Definiert in Zeile 321 der Datei eyefi.c.

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

Definiert in Zeile 318 der Datei eyefi.c.

#define MAX_NETWORK   9

Definiert in Zeile 395 der Datei eyefi.c.

#define PWD_LEN   32

Definiert in Zeile 396 der Datei eyefi.c.

#define WEP_40_KEY_BYTES   5

Definiert in Zeile 27 der Datei eyefi.c.

#define WEP_KEY_BYTES   13

Definiert in Zeile 26 der Datei eyefi.c.

#define WPA_KEY_BYTES   32

Definiert in Zeile 25 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 43 der Datei eyefi.c.

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

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

Definiert in Zeile 151 der Datei eyefi.c.

152 {
154 }
static void confirm_add_network_cb ( unsigned int  btn)
static

Definiert in Zeile 491 der Datei eyefi.c.

492 {
493  int n,i;
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 421 der Datei eyefi.c.

static u8* convert_ascii_to_hex ( char *  ascii)
static

Definiert in Zeile 172 der Datei eyefi.c.

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

Definiert in Zeile 347 der Datei eyefi.c.

348 {
349  return eyefi_networkAction('a', SSID, pwd);
350 }
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 462 der Datei eyefi.c.

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

Definiert in Zeile 337 der Datei eyefi.c.

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

Definiert in Zeile 353 der Datei eyefi.c.

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

Definiert in Zeile 403 der Datei eyefi.c.

404 {
405  running = 0;
407 }
static char* eyefi_filename ( const char *  nm)
static

Definiert in Zeile 236 der Datei eyefi.c.

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

Definiert in Zeile 324 der Datei eyefi.c.

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

Definiert in Zeile 263 der Datei eyefi.c.

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

Definiert in Zeile 285 der Datei eyefi.c.

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

Definiert in Zeile 374 der Datei eyefi.c.

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

Definiert in Zeile 342 der Datei eyefi.c.

343 {
344  return eyefi_networkAction('t', SSID, pwd);
345 }
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 409 der Datei eyefi.c.

static int eyefi_writeFile ( const char *  filename)
static

Definiert in Zeile 248 der Datei eyefi.c.

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

Definiert in Zeile 190 der Datei eyefi.c.

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

Definiert in Zeile 207 der Datei eyefi.c.

208 {
209  u8 *hex_pass;
210  int pass_len = strlen(pass);
211  memset(key, 0, sizeof(*key));
212 
213  switch (pass_len) {
214  case WPA_KEY_BYTES*2:
215  case WEP_KEY_BYTES*2:
216  case WEP_40_KEY_BYTES*2:
217  if (hex_only(pass))
218  {
219  hex_pass = convert_ascii_to_hex(pass);
220  if (!hex_pass)
221  return -EINVAL;
222  key->len = pass_len/2;
223  memcpy(&key->key[0], hex_pass, key->len);
224  break;
225  }
226  // Fall through to default case
227  default:
228  key->len = WPA_KEY_BYTES;
229  pbkdf2_sha1(pass, essid, strlen(essid), 4096, &key->key[0], WPA_KEY_BYTES);
230  break;
231  }
232  return 0;
233 }
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 431 der Datei eyefi.c.

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

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 108 der Datei eyefi.c.

unsigned char bytes

Definiert in Zeile 107 der Datei eyefi.c.

_eyefi_interface eyefi_buf
static

Definiert in Zeile 149 der Datei eyefi.c.

char eyefi_password[PWD_LEN+1]
static

Definiert in Zeile 400 der Datei eyefi.c.

char eyefi_selectedNetwork[ESSID_LEN+1]
static

Definiert in Zeile 399 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 101 der Datei eyefi.c.

u8 len

Definiert in Zeile 100 der Datei eyefi.c.

struct mpopup_item popup_eyefi[MAX_NETWORK+1]
static

Definiert in Zeile 398 der Datei eyefi.c.

int running = 0
static

Definiert in Zeile 148 der Datei eyefi.c.

unsigned char subcommand

Definiert in Zeile 106 der Datei eyefi.c.