2 * Davicom DM9601 USB 1.1 Ethernet Driver.
3 * Copyright (c) 2008, 2011 Siarzhuk Zharski <imker@gmx.li>
4 * Distributed under the terms of the MIT license.
14 #include <driver_settings.h>
21 static char *gLogFilePath
= NULL
;
23 bool gTraceOn
= false;
24 bool gTruncateLogFile
= false;
25 bool gAddTimeStamp
= true;
26 bool gTraceState
= false;
27 bool gTraceRX
= false;
28 bool gTraceTX
= false;
29 bool gTraceStats
= false;
35 if (gLogFilePath
== NULL
)
38 int flags
= O_WRONLY
| O_CREAT
| ((gTruncateLogFile
) ? O_TRUNC
: 0);
39 int fd
= open(gLogFilePath
, flags
, 0666);
43 mutex_init(&gLogLock
, DRIVER_NAME
"-logging");
50 void *handle
= load_driver_settings(DRIVER_NAME
);
54 gTraceOn
= get_driver_boolean_parameter(handle
, "trace", gTraceOn
, true);
55 gTraceState
= get_driver_boolean_parameter(handle
,
56 "trace_state", gTraceState
, true);
57 gTraceRX
= get_driver_boolean_parameter(handle
, "trace_rx", gTraceRX
, true);
58 gTraceTX
= get_driver_boolean_parameter(handle
, "trace_tx", gTraceTX
, true);
59 gTraceStats
= get_driver_boolean_parameter(handle
,
60 "trace_stats", gTraceStats
, true);
61 gTruncateLogFile
= get_driver_boolean_parameter(handle
,
62 "reset_logfile", gTruncateLogFile
, true);
63 gAddTimeStamp
= get_driver_boolean_parameter(handle
,
64 "add_timestamp", gAddTimeStamp
, true);
65 const char * logFilePath
= get_driver_parameter(handle
,
66 "logfile", NULL
, "/var/log/"DRIVER_NAME
".log");
67 if (logFilePath
!= NULL
) {
68 gLogFilePath
= strdup(logFilePath
);
71 unload_driver_settings(handle
);
80 if (gLogFilePath
!= NULL
) {
81 mutex_destroy(&gLogLock
);
87 void usb_davicom_trace(bool force
, const char* func
, const char *fmt
, ...)
89 if (!(force
|| gTraceOn
)) {
94 static const char *prefix
= "\33[33m"DRIVER_NAME
":\33[0m";
95 static char buffer
[1024];
96 char *buf_ptr
= buffer
;
97 if (gLogFilePath
== NULL
) {
98 strlcpy(buffer
, prefix
, sizeof(buffer
));
99 buf_ptr
+= strlen(prefix
);
103 bigtime_t time
= system_time();
104 uint32 msec
= time
/ 1000;
105 uint32 sec
= msec
/ 1000;
106 sprintf(buf_ptr
, "%02" B_PRId32
".%02" B_PRId32
".%03" B_PRId32
":",
107 sec
/ 60, sec
% 60, msec
% 1000);
108 buf_ptr
+= strlen(buf_ptr
);
112 sprintf(buf_ptr
, "%s::", func
);
113 buf_ptr
+= strlen(buf_ptr
);
116 va_start(arg_list
, fmt
);
117 vsprintf(buf_ptr
, fmt
, arg_list
);
120 if (gLogFilePath
== NULL
) {
125 mutex_lock(&gLogLock
);
126 int fd
= open(gLogFilePath
, O_WRONLY
| O_APPEND
);
128 write(fd
, buffer
, strlen(buffer
));
131 mutex_unlock(&gLogLock
);