DEFINE_HOST_PROG(IP, ip, [/sbin/ip])
DEFINE_HOST_PROG(UDHCPC, udhcpc, [/sbin/udhcpc])
+AC_ARG_WITH(
+ [tftp],
+ [AS_HELP_STRING([--with-tftp=TYPE],
+ [Use TYPE-type ftp client (either hpa or busybox) [default=runtime-check]]
+ )],
+ [],
+ [with_tftp=detect]
+)
+
+case x$with_tftp in
+'xhpa')
+ tftp_type='TFTP_TYPE_HPA'
+ ;;
+'xbusybox')
+ tftp_type='TFTP_TYPE_BUSYBOX'
+ ;;
+*)
+ tftp_type='TFTP_TYPE_UNKNOWN'
+ ;;
+esac
+
+AC_DEFINE_UNQUOTED(TFTP_TYPE, $tftp_type, [tftp client type])
+
default_cflags="--std=gnu99 -g \
-Wall -W -Wunused -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wredundant-decls"
return NULL;
}
+static enum tftp_type check_tftp_type(void *ctx)
+{
+ const char *argv[] = { pb_system_apps.tftp, "-V", NULL };
+ struct process *process;
+ enum tftp_type type;
+
+ process = process_create(ctx);
+ process->path = pb_system_apps.tftp;
+ process->argv = argv;
+ process->keep_stdout = true;
+ process_run_sync(process);
+
+ if (!process->stdout_buf || process->stdout_len == 0) {
+ pb_log("Can't check TFTP client type!\n");
+ type = TFTP_TYPE_BROKEN;
+
+ } else if (memmem(process->stdout_buf, process->stdout_len,
+ "tftp-hpa", strlen("tftp-hpa"))) {
+ pb_debug("Found TFTP client type: tftp-hpa\n");
+ type = TFTP_TYPE_HPA;
+
+ } else if (memmem(process->stdout_buf, process->stdout_len,
+ "BusyBox", strlen("BusyBox"))) {
+ pb_debug("Found TFTP client type: BusyBox tftp\n");
+ type = TFTP_TYPE_BUSYBOX;
+
+ } else {
+ pb_log("Unknown TFTP client type!\n");
+ type = TFTP_TYPE_BROKEN;
+ }
+
+ process_release(process);
+ return type;
+}
+
/**
* pb_load_tftp - Loads a remote file via tftp and returns the local file path.
*
char *local;
struct process *process;
- local = local_name(ctx);
+ if (tftp_type == TFTP_TYPE_UNKNOWN)
+ tftp_type = check_tftp_type(ctx);
- if (!local)
+ if (tftp_type == TFTP_TYPE_BROKEN)
return NULL;
- /* first try busybox tftp args */
+ local = local_name(ctx);
+ if (!local)
+ return NULL;
- p = argv;
- *p++ = pb_system_apps.tftp; /* 1 */
- *p++ = "-g"; /* 2 */
- *p++ = "-l"; /* 3 */
- *p++ = local; /* 4 */
- *p++ = "-r"; /* 5 */
- *p++ = url->path; /* 6 */
- *p++ = url->host; /* 7 */
- if (url->port)
- *p++ = url->port; /* 8 */
- *p++ = NULL; /* 9 */
+ if (tftp_type == TFTP_TYPE_BUSYBOX) {
+ /* first try busybox tftp args */
+
+ p = argv;
+ *p++ = pb_system_apps.tftp; /* 1 */
+ *p++ = "-g"; /* 2 */
+ *p++ = "-l"; /* 3 */
+ *p++ = local; /* 4 */
+ *p++ = "-r"; /* 5 */
+ *p++ = url->path; /* 6 */
+ *p++ = url->host; /* 7 */
+ if (url->port)
+ *p++ = url->port; /* 8 */
+ *p++ = NULL; /* 9 */
+ } else {
+ p = argv;
+ *p++ = pb_system_apps.tftp; /* 1 */
+ *p++ = "-m"; /* 2 */
+ *p++ = "binary"; /* 3 */
+ *p++ = url->host; /* 4 */
+ if (url->port)
+ *p++ = url->port; /* 5 */
+ *p++ = "-c"; /* 6 */
+ *p++ = "get"; /* 7 */
+ *p++ = url->path; /* 8 */
+ *p++ = local; /* 9 */
+ *p++ = NULL; /* 10 */
+ }
if (url_data) {
process = process_create(ctx);
result = process_run_simple_argv(ctx, argv);
}
- if (!result)
- return local;
-
- /* next try tftp-hpa args */
- p = argv;
- *p++ = pb_system_apps.tftp; /* 1 */
- *p++ = "-m"; /* 2 */
- *p++ = "binary"; /* 3 */
- *p++ = url->host; /* 4 */
- if (url->port)
- *p++ = url->port; /* 5 */
- *p++ = "-c"; /* 6 */
- *p++ = "get"; /* 7 */
- *p++ = url->path; /* 8 */
- *p++ = local; /* 9 */
- *p++ = NULL; /* 10 */
-
- if (url_data) {
- process->argv = argv;
- result = process_run_async(process);
- if (result)
- process_release(process);
- } else {
- result = process_run_simple_argv(ctx, argv);
- }
-
if (!result)
return local;