00001
00002
00003
00004
00005 #include <string.h>
00006 #include "modem.h"
00007
00008 #ifndef USE_PLUGINS
00009 #include "hitachi.h"
00010 #endif
00011
00012
00013
00014 static int DEBUG = 0;
00015
00016
00017
00018
00019 static char *log_file = NULL;
00020
00021
00022
00023
00024
00025 static int my_fake_syslog (const char *file, const char * fmt,...) { return 0; }
00026
00027
00028
00029
00030
00031
00032 static int (*my_syslog) (const char *file, const char * fmt,...) = my_fake_syslog;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 void init_modem_syslog (int (*syslog)(const char *file, const char * fmt,...),
00047 char *log,
00048 int debug)
00049 {
00050 if ((syslog != NULL) && (log != NULL))
00051 {
00052 my_syslog = syslog;
00053 log_file = log;
00054 DEBUG = debug;
00055 }
00056 else { my_syslog = my_fake_syslog; }
00057
00058 return;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 int get_modem_manufacturor (struct dhcp_packet *packet)
00072 {
00073 char *haddr;
00074
00075
00076
00077
00078
00079 haddr = packets_get_chaddr_no_separator(packet);
00080
00081 #ifdef USE_PLUGINS
00082
00083 return (modem_conf_get_id(haddr));
00084
00085 #else
00086
00087 if (strncmp(haddr, HITACHI_MARK1, strlen(HITACHI_MARK1)) == 0) { return MODEM_HITACHI; }
00088 if (strncmp(haddr, HITACHI_MARK2, strlen(HITACHI_MARK2)) == 0) { return MODEM_HITACHI; }
00089 if (strncmp(haddr, SAGEM_MARK1, strlen(SAGEM_MARK1)) == 0) { return MODEM_SAGEM; }
00090 if (strncmp(haddr, SAGEM_MARK2, strlen(SAGEM_MARK2)) == 0) { return MODEM_SAGEM; }
00091 return MODEM_UNKNOWN;
00092
00093 #endif
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 char *calculate_modem_mac_address (struct dhcp_packet *packet, int manufacturor)
00106 {
00107 char *real_haddr;
00108 static char haddr_hexa[DHCP_P_STR_HADDR_SIZE_EXACT];
00109
00110 #ifndef USE_PLUGINS
00111 #else
00112 char *new_haddr;
00113 char* (*calculate_mac_address)(char*);
00114 #endif
00115
00116 real_haddr = packets_get_chaddr_no_separator(packet);
00117 memset ((void*)haddr_hexa, 0, DHCP_P_STR_HADDR_SIZE_EXACT);
00118 strncpy (haddr_hexa, real_haddr, DHCP_P_STR_HADDR_SIZE_EXACT-1);
00119
00120 #ifndef USE_PLUGINS
00121
00122
00123
00124
00125
00126
00127
00128 if (manufacturor == MODEM_HITACHI)
00129 {
00130 calculate_mac (haddr_hexa);
00131
00132 if (DEBUG > 1)
00133 {
00134 my_syslog (log_file, "[DEBUG] [%s:%d] calculate_modem_mac_address: HITACHI MAC address [%s] => [%s]",
00135 __FILE__, __LINE__, real_haddr, haddr_hexa);
00136 }
00137
00138 return haddr_hexa;
00139 }
00140
00141
00142
00143
00144
00145 if (DEBUG > 1)
00146 {
00147 my_syslog (log_file, "[DEBUG] [%s:%d] calculate_modem_mac_address: UNKNOWN MAC address [%s] => [%s]",
00148 __FILE__, __LINE__, real_haddr, haddr_hexa);
00149 }
00150
00151 return haddr_hexa;
00152
00153 #else
00154
00155 calculate_mac_address = (char*(*)(char*))modem_conf_get_function(manufacturor);
00156 new_haddr = (*calculate_mac_address)(haddr_hexa);
00157
00158 if (DEBUG > 1)
00159 {
00160 my_syslog (log_file, "[DEBUG] [%s:%d] calculate_modem_mac_address: MAC [%s] => [%s]",
00161 __FILE__, __LINE__, real_haddr, new_haddr);
00162 }
00163
00164 return new_haddr;
00165
00166 #endif
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 char *id_manufacturor_to_string (int id)
00177 {
00178 #ifndef USE_PLUGINS
00179
00180 static char m_hitachi[] = "HITACHI";
00181 static char m_sagem[] = "SAGEM";
00182 static char m_unknown[] = "UNKNOWN";
00183
00184 switch (id)
00185 {
00186 case MODEM_HITACHI: return m_hitachi;
00187 case MODEM_SAGEM: return m_sagem;
00188 default: return m_unknown;
00189 }
00190
00191 return m_unknown;
00192
00193 #else
00194
00195 return modem_conf_get_tag_name(id);
00196
00197 #endif
00198 }
00199
00200
00201
00202