prefix the network types with NET_
fix vprintf vs printf bug do some strdups with optargs
This commit is contained in:
parent
6afcff686f
commit
84bbcda46c
4 changed files with 56 additions and 41 deletions
|
@ -16,7 +16,7 @@ int eyefi_printf(const char *fmt, ...)
|
|||
int r;
|
||||
|
||||
va_start(args, fmt);
|
||||
r = printf(fmt, args);
|
||||
r = vprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return r;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "eyefi-config.h"
|
||||
|
||||
int eyefi_debug_level = 0;
|
||||
int eyefi_debug_level = 1;
|
||||
|
||||
int eyefi_printf(const char *fmt, ...)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ int eyefi_printf(const char *fmt, ...)
|
|||
int r;
|
||||
|
||||
va_start(args, fmt);
|
||||
r = printf(fmt, args);
|
||||
r = vprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return r;
|
||||
|
@ -40,9 +40,12 @@ char *eyefi_file_on(enum eyefi_file file, char *mnt)
|
|||
{
|
||||
char *filename = eyefi_file_name(file);
|
||||
char *full = malloc(PATHNAME_MAX);
|
||||
|
||||
if (!full)
|
||||
return NULL;
|
||||
|
||||
sprintf(&full[0], "%s/EyeFi/%s", mnt, filename);
|
||||
debug_printf(4, "eyefile nr: %d on '%s' is: '%s'\n", file, mnt, &full[0]);
|
||||
debug_printf(3, "eyefile nr: %d on '%s' is: '%s'\n", file, mnt, &full[0]);
|
||||
return full;
|
||||
}
|
||||
|
||||
|
@ -139,10 +142,13 @@ void align_buf(void)
|
|||
*/
|
||||
void zero_card_files(void)
|
||||
{
|
||||
//write_to(REQM, eyefi_buf, EYEFI_BUF_SIZE);
|
||||
write_to(REQC, eyefi_buf, EYEFI_BUF_SIZE);
|
||||
write_to(RSPM, eyefi_buf, EYEFI_BUF_SIZE);
|
||||
write_to(RSPC, eyefi_buf, EYEFI_BUF_SIZE);
|
||||
char zbuf[EYEFI_BUF_SIZE];
|
||||
|
||||
memset(&zbuf[0], 0, EYEFI_BUF_SIZE);
|
||||
//write_to(REQM, zbuf, EYEFI_BUF_SIZE);
|
||||
write_to(REQC, zbuf, EYEFI_BUF_SIZE);
|
||||
write_to(RSPM, zbuf, EYEFI_BUF_SIZE);
|
||||
write_to(RSPC, zbuf, EYEFI_BUF_SIZE);
|
||||
|
||||
read_from(REQM);
|
||||
read_from(REQC);
|
||||
|
@ -331,19 +337,21 @@ char *net_test_state_name(u8 state)
|
|||
return net_test_states[state];
|
||||
}
|
||||
|
||||
char *net_types[] = {
|
||||
const char *net_types[] = {
|
||||
"No security",
|
||||
"WEP",
|
||||
"WPA",
|
||||
"unknown1",
|
||||
"WPA2",
|
||||
};
|
||||
const char net_type_unknown[] = "unknown";
|
||||
|
||||
char *net_type_name(u8 type)
|
||||
const char *net_type_name(u8 type)
|
||||
{
|
||||
int size = ARRAY_SIZE(net_types);
|
||||
debug_printf(3, "%s(%d): '%s' size: %d\n", __func__, type, net_types[type], size);
|
||||
if (type >= size)
|
||||
return "unknown";
|
||||
return net_type_unknown;
|
||||
return net_types[type];
|
||||
}
|
||||
|
||||
|
@ -502,7 +510,7 @@ struct card_info_rsp_key *fetch_card_key(void)
|
|||
int issue_noarg_command(u8 cmd)
|
||||
{
|
||||
struct noarg_request req;
|
||||
printf("%s() cmd: %d\n", __func__, cmd);
|
||||
debug_printf(4, "%s() cmd: %d\n", __func__, cmd);
|
||||
req.req = cmd;
|
||||
write_struct(REQM, &req);
|
||||
return wait_for_response();
|
||||
|
@ -587,16 +595,16 @@ int get_log_at_offset(u32 offset)
|
|||
|
||||
void add_log_piece(u8 *log, int log_len, u8 *piece, int piece_pos, int piece_size)
|
||||
{
|
||||
debug_printf(0, "%s(%p, %d, %p, %d, %d)\n", __func__, log, log_len, piece, piece_pos, piece_size);
|
||||
debug_printf(2, "%s(%p, %d, %p, %d, %d)\n", __func__, log, log_len, piece, piece_pos, piece_size);
|
||||
if (piece_pos + piece_size > log_len) {
|
||||
int overflow_by = (piece_pos + piece_size) - log_len;
|
||||
int piece_overrun_pos = piece_size - overflow_by;
|
||||
piece_size -= overflow_by;
|
||||
memcpy(&log[0], &piece[piece_overrun_pos], overflow_by);
|
||||
debug_printf(0, "writing %d bytes to logbuf[0] from piece[%d]\n",
|
||||
debug_printf(2, "writing %d bytes to logbuf[0] from piece[%d]\n",
|
||||
overflow_by, piece_overrun_pos);
|
||||
}
|
||||
debug_printf(0, "writing %d bytes to logbuf[%d]\n", piece_size, piece_pos);
|
||||
debug_printf(2, "writing %d bytes to logbuf[%d]\n", piece_size, piece_pos);
|
||||
memcpy(&log[piece_pos], piece, piece_size);
|
||||
}
|
||||
|
||||
|
|
|
@ -200,10 +200,10 @@ struct byte_response {
|
|||
};
|
||||
|
||||
enum net_type {
|
||||
UNSECURED,
|
||||
WEP,
|
||||
WPA,
|
||||
WPA2
|
||||
NET_UNSECURED,
|
||||
NET_WEP,
|
||||
NET_WPA,
|
||||
NET_WPA2
|
||||
};
|
||||
|
||||
#define ESSID_LEN 32
|
||||
|
@ -290,7 +290,7 @@ int card_info_cmd(enum card_info_subcommand cmd);
|
|||
void *eyefi_response(void);
|
||||
struct card_info_rsp_key *fetch_card_key(void);
|
||||
struct scanned_net_list *scan_nets(void);
|
||||
char *net_type_name(u8 type);
|
||||
const char *net_type_name(u8 type);
|
||||
struct configured_net_list *fetch_configured_nets(void);
|
||||
int issue_noarg_command(u8 cmd);
|
||||
char *net_test_state_name(u8 state);
|
||||
|
|
49
eyefi-unix.c
49
eyefi-unix.c
|
@ -104,11 +104,14 @@ int try_connection_to(char *essid, char *wpa_ascii)
|
|||
{
|
||||
int i;
|
||||
int ret = -1;
|
||||
const char *type;
|
||||
|
||||
char *type = net_type_name(WPA);
|
||||
type = net_type_name(NET_WPA);
|
||||
if (!wpa_ascii)
|
||||
type = net_type_name(UNSECURED);
|
||||
eyefi_printf("trying to connect to %s network: '%s'", type, essid);
|
||||
type = net_type_name(NET_UNSECURED);
|
||||
|
||||
eyefi_printf("trying to connect to network: '%s'", essid);
|
||||
eyefi_printf("of type: '%s'\n", type);
|
||||
if (wpa_ascii)
|
||||
eyefi_printf(" with passphrase: '%s'", wpa_ascii);
|
||||
fflush(NULL);
|
||||
|
@ -155,7 +158,7 @@ int try_connection_to(char *essid, char *wpa_ascii)
|
|||
int print_log(void)
|
||||
{
|
||||
int i;
|
||||
char *resbuf = malloc(EYEFI_BUF_SIZE*4);
|
||||
u8 *resbuf = malloc(EYEFI_BUF_SIZE*4);
|
||||
int total_bytes;
|
||||
|
||||
total_bytes = get_log_into(resbuf);
|
||||
|
@ -228,13 +231,13 @@ void usage(void)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1)
|
||||
usage();
|
||||
|
||||
debug_printf(3, "%s starting...\n", argv[0]);
|
||||
|
||||
//static int passed_wep = 0;
|
||||
//static int passed_wpa = 0;
|
||||
int option_index;
|
||||
char c;
|
||||
int magic0 = 19790111;
|
||||
char *essid = NULL;
|
||||
char *passwd = NULL;
|
||||
int magic1 = 1111979;
|
||||
char network_action = 0;
|
||||
static int force = 0;
|
||||
static struct option long_options[] = {
|
||||
//{"wep", 'x', &passed_wep, 1},
|
||||
|
@ -243,11 +246,11 @@ int main(int argc, char **argv)
|
|||
{"help", 'h', NULL, 1},
|
||||
};
|
||||
|
||||
int option_index;
|
||||
char c;
|
||||
char *essid = NULL;
|
||||
char *passwd = NULL;
|
||||
char network_action = 0;
|
||||
if (argc == 1)
|
||||
usage();
|
||||
|
||||
debug_printf(3, "%s starting...\n", argv[0]);
|
||||
|
||||
debug_printf(3, "about to parse arguments\n");
|
||||
while ((c = getopt_long_only(argc, argv, "a:bcd:kflmp:r:st:z",
|
||||
&long_options[0], &option_index)) != -1) {
|
||||
|
@ -259,7 +262,7 @@ int main(int argc, char **argv)
|
|||
case 'a':
|
||||
case 't':
|
||||
case 'r':
|
||||
essid = optarg;
|
||||
essid = strdup(optarg);
|
||||
network_action = c;
|
||||
break;
|
||||
case 'b':
|
||||
|
@ -285,23 +288,24 @@ int main(int argc, char **argv)
|
|||
print_card_mac();
|
||||
break;
|
||||
case 'p':
|
||||
passwd = optarg;
|
||||
passwd = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
scan_print_nets();
|
||||
break;
|
||||
case 'z': {
|
||||
extern void testit0(void);
|
||||
extern void testit0(void);
|
||||
testit0();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
debug_printf(3, "after arguments essid: '%s' passwd: '%s'\n", essid, passwd);
|
||||
|
||||
debug_printf(3, "after arguments1 essid: '%s' passwd: '%s'\n", essid, passwd);
|
||||
if (network_action && essid) {
|
||||
int ret = 0;
|
||||
init_card();
|
||||
|
@ -327,6 +331,9 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(essid);
|
||||
free(passwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue