2 * ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
3 * Copyright (c) 2008,2011 S.Zharski <imker@gmx.li>
4 * Distributed under the terms of the MIT license.
6 * Heavily based on code of the
7 * Driver for USB Ethernet Control Model devices
8 * Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
9 * Distributed under the terms of the MIT license.
20 #include <driver_settings.h>
24 bool gTraceOn
= false;
25 bool gTruncateLogFile
= false;
26 bool gAddTimeStamp
= true;
27 bool gTraceFlow
= false;
28 static char *gLogFilePath
= NULL
;
34 if (gLogFilePath
== NULL
)
37 int flags
= O_WRONLY
| O_CREAT
| ((gTruncateLogFile
) ? O_TRUNC
: 0);
38 int fd
= open(gLogFilePath
, flags
, 0666);
42 mutex_init(&gLogLock
, DRIVER_NAME
"-logging");
48 void *handle
= load_driver_settings(DRIVER_NAME
);
52 gTraceOn
= get_driver_boolean_parameter(handle
, "trace", gTraceOn
, true);
53 gTraceFlow
= get_driver_boolean_parameter(handle
, "trace_flow",
55 gTruncateLogFile
= get_driver_boolean_parameter(handle
, "truncate_logfile",
56 gTruncateLogFile
, true);
57 gAddTimeStamp
= get_driver_boolean_parameter(handle
, "add_timestamp",
59 const char * logFilePath
= get_driver_parameter(handle
, "logfile",
60 NULL
, "/var/log/"DRIVER_NAME
".log");
61 if (logFilePath
!= NULL
) {
62 gLogFilePath
= strdup(logFilePath
);
65 unload_driver_settings(handle
);
71 void release_settings()
73 if (gLogFilePath
!= NULL
) {
74 mutex_destroy(&gLogLock
);
80 void usb_asix_trace(bool force
, const char* func
, const char *fmt
, ...)
82 if (!(force
|| gTraceOn
)) {
87 static const char *prefix
= "\33[33m"DRIVER_NAME
":\33[0m";
88 static char buffer
[1024];
89 char *buf_ptr
= buffer
;
90 if (gLogFilePath
== NULL
) {
91 strlcpy(buffer
, prefix
, sizeof(buffer
));
92 buf_ptr
+= strlen(prefix
);
96 bigtime_t time
= system_time();
97 uint32 msec
= time
/ 1000;
98 uint32 sec
= msec
/ 1000;
99 sprintf(buf_ptr
, "%02" B_PRId32
".%02" B_PRId32
".%03" B_PRId32
":",
100 sec
/ 60, sec
% 60, msec
% 1000);
101 buf_ptr
+= strlen(buf_ptr
);
105 sprintf(buf_ptr
, "%s::", func
);
106 buf_ptr
+= strlen(buf_ptr
);
109 va_start(arg_list
, fmt
);
110 vsprintf(buf_ptr
, fmt
, arg_list
);
113 if (gLogFilePath
== NULL
) {
118 mutex_lock(&gLogLock
);
119 int fd
= open(gLogFilePath
, O_WRONLY
| O_APPEND
);
121 write(fd
, buffer
, strlen(buffer
));
124 mutex_unlock(&gLogLock
);