Go to the source code of this file.
Functions | |
const char * | get_sysset_macAddress (void) |
const char * | get_wired_macAddress (void) |
const char * | get_wireless_macAddress (void) |
const char * | get_wlanmactxt_macAddress (void) |
const char * | get_software_version_commercial (void) |
const char * | get_software_version (void) |
int | get_public_key (char **pubkey) |
This file provides system call functionality to execute commands and such
Copyright (C) 2007 iRex Technologies B.V. All rights reserved.
Definition in file system.h.
int get_public_key | ( | char ** | pubkey | ) |
Definition at line 350 of file system.c.
00351 { 00352 int bytes = 0; 00353 int i; 00354 FILE *f = fopen(PUBLIC_KEY_FILE, "r"); 00355 if (f == NULL) 00356 { 00357 return -1; // -1 means file opening failed 00358 } 00359 00360 *pubkey = (char *) malloc(MAX_PUBKEY_SIZE); 00361 if (*pubkey == NULL) 00362 { 00363 ERREG_ERRORPRINTF("Error: cannot allocate %d bytes for public key", MAX_PUBKEY_SIZE); 00364 return 1; 00365 } 00366 00367 if ((bytes = fread(*pubkey, 1, MAX_PUBKEY_SIZE, f)) == MAX_PUBKEY_SIZE) 00368 { 00369 ERREG_ERRORPRINTF("Error reading Public Key (too big)"); 00370 free(*pubkey); 00371 *pubkey = NULL; 00372 return -2; 00373 } 00374 00375 if (!feof(f)) 00376 { 00377 ERREG_ERRORPRINTF("Error reading Public Key (not EOF)"); 00378 free(*pubkey); 00379 *pubkey = NULL; 00380 return -3; 00381 } 00382 00383 (*pubkey)[bytes] = '\0'; 00384 00385 // Test to see if this looks like a public key 00386 for (i = 0; i < bytes; i++) 00387 { 00388 if (!is_pubkey_char((*pubkey)[i])) 00389 { 00390 ERREG_ERRORPRINTF("Error: this does not look like a public key!"); 00391 free(*pubkey); 00392 *pubkey = NULL; 00393 return -5; 00394 } 00395 } 00396 00397 ERREG_LOGPRINTF("software publicKey [%s]", *pubkey); 00398 00399 fclose(f); 00400 return bytes; 00401 }
const char* get_software_version | ( | void | ) |
Definition at line 297 of file system.c.
00298 { 00299 static char version[VERSION_LENGTH] = ""; 00300 00301 FILE *fd = fopen(VERSION_FILE, "r"); 00302 if (fd) 00303 { 00304 fgets(version, sizeof(version)-1, fd); 00305 fclose(fd); 00306 00307 char *new_line = strchr(version, '\n'); 00308 if (new_line) 00309 { 00310 *new_line = '\0'; 00311 } 00312 00313 ERREG_LOGPRINTF("software version [%s]", version); 00314 } 00315 00316 return version; 00317 }
const char* get_software_version_commercial | ( | void | ) |
Definition at line 319 of file system.c.
00320 { 00321 static char version[VERSION_LENGTH] = ""; 00322 00323 FILE *fd = fopen(VERSION_COMMERCIAL_FILE, "r"); 00324 if (fd) 00325 { 00326 fgets(version, sizeof(version)-1, fd); 00327 fclose(fd); 00328 00329 char *new_line = strchr(version, '\n'); 00330 if (new_line) 00331 { 00332 *new_line = '\0'; 00333 } 00334 00335 ERREG_LOGPRINTF("software version [%s]", version); 00336 } 00337 00338 return version; 00339 }
const char* get_sysset_macAddress | ( | void | ) |
Definition at line 41 of file system.c.
00042 { 00043 FILE *POUT = 0; 00044 int nProcessRet = 0; 00045 00046 static char mac_address[MAC_LENGTH + 6] = "00-00-00-00-00-00"; 00047 00048 POUT = popen("sysset -r -b -a 262 -l 6", "r"); 00049 if (POUT == NULL) 00050 { 00051 ERREG_ERRORPRINTF("Could not read EUI64"); 00052 } 00053 else 00054 { 00055 int nChar; 00056 int index = 0; 00057 char szBuffer[PROCESS_BUFFER_MAX + 1]; 00058 00059 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX)) 00060 { 00061 szBuffer[index] = (char)nChar; 00062 index++; 00063 } 00064 szBuffer[index] = '\0'; 00065 ERREG_LOGPRINTF("echoed %s", szBuffer); 00066 00067 nProcessRet = pclose(POUT); 00068 if (WIFEXITED(nProcessRet)) 00069 { 00070 if (WEXITSTATUS(nProcessRet) == 0) 00071 { 00072 int nLen; 00073 00074 // Normal case 00075 // 00076 // The string as retrieved from sysset is 15 (MAX_HEX_DECORATION+MAC_LENGTH+1) characters long. 00077 // e.g 0x00167c000000\n 00078 // The first two (MAX_HEX_DECORATION) characters need to be removed 00079 // and dashes inserted to separate byte values 00080 // resulting in: 00-16-7c-00-00-00 00081 // 00082 ERREG_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet)); 00083 nLen = strlen(szBuffer); 00084 if (nLen != MAC_LENGTH + 2 + 1) 00085 { 00086 ERREG_ERRORPRINTF("Wrong length [%d] of MAC address [%s]", nLen, szBuffer); 00087 } 00088 else 00089 { 00090 char *cp1 = mac_address; 00091 char *cp2 = szBuffer + MAC_HEX_DECORATION; 00092 for (index = 0; index < MAC_LENGTH; index += 2) 00093 { 00094 // m.s. nibble 00095 *cp1 = toupper(*cp2); 00096 cp1++; 00097 cp2++; 00098 00099 // l.s. nibble 00100 *cp1 = toupper(*cp2); 00101 cp1++; 00102 cp2++; 00103 00104 // skip byte separator 00105 cp1++; 00106 } 00107 } 00108 } 00109 else 00110 { 00111 ERREG_ERRORPRINTF("pclose returned %d. Error retrieving MAC", WEXITSTATUS(nProcessRet)); 00112 } 00113 } 00114 else 00115 { 00116 ERREG_ERRORPRINTF("pclose did not exit normally"); 00117 } 00118 } 00119 00120 ERREG_LOGPRINTF("return [%s]", mac_address); 00121 return mac_address; 00122 }
const char* get_wired_macAddress | ( | void | ) |
Definition at line 124 of file system.c.
00125 { 00126 FILE *POUT = 0; 00127 int nProcessRet = 0; 00128 00129 static char mac_address[MAC_LENGTH + 6] = "00-00-00-00-00-00"; 00130 00131 00132 POUT = popen("/usr/bin/wired.sh mac | tail -1", "r"); 00133 if (POUT == NULL) 00134 { 00135 ERREG_ERRORPRINTF("Could not read wired MAC address"); 00136 } 00137 else 00138 { 00139 int nChar; 00140 int index = 0; 00141 char szBuffer[PROCESS_BUFFER_MAX + 1]; 00142 00143 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX)) 00144 { 00145 szBuffer[index] = (char)nChar; 00146 index++; 00147 } 00148 szBuffer[index] = '\0'; 00149 ERREG_LOGPRINTF("echoed %s", szBuffer); 00150 00151 nProcessRet = pclose(POUT); 00152 if (WIFEXITED(nProcessRet)) 00153 { 00154 if (WEXITSTATUS(nProcessRet) == 0) 00155 { 00156 int nLen; 00157 00158 // Normal case 00159 // 00160 // The string as retrieved from wirede.sh 17 (MAC_LENGTH+5+1) characters long. 00161 // e.g 00-16-7c-00-00-00\n 00162 ERREG_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet)); 00163 nLen = strlen(szBuffer); 00164 if (nLen != MAC_LENGTH + 5 + 1) 00165 { 00166 ERREG_ERRORPRINTF("Wrong length [%d] of MAC address [%s]", nLen, szBuffer); 00167 } 00168 else 00169 { 00170 strncpy(mac_address, szBuffer, MAC_LENGTH + 5); 00171 } 00172 } 00173 else 00174 { 00175 ERREG_ERRORPRINTF("pclose returned %d. Error retrieving MAC", WEXITSTATUS(nProcessRet)); 00176 } 00177 } 00178 else 00179 { 00180 ERREG_ERRORPRINTF("pclose did not exit normally"); 00181 } 00182 } 00183 00184 ERREG_LOGPRINTF("return [%s]", mac_address); 00185 return mac_address; 00186 }
const char* get_wireless_macAddress | ( | void | ) |
Definition at line 189 of file system.c.
00190 { 00191 FILE *POUT = 0; 00192 int nProcessRet = 0; 00193 00194 static char mac_address[MAC_LENGTH + 6] = "00-00-00-00-00-00"; 00195 00196 00197 POUT = popen("/usr/bin/wireless.sh mac | tail -1", "r"); 00198 if (POUT == NULL) 00199 { 00200 ERREG_ERRORPRINTF("Could not read wireless MAC address"); 00201 } 00202 else 00203 { 00204 int nChar; 00205 int index = 0; 00206 char szBuffer[PROCESS_BUFFER_MAX + 1]; 00207 00208 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX)) 00209 { 00210 szBuffer[index] = (char)nChar; 00211 index++; 00212 } 00213 szBuffer[index] = '\0'; 00214 ERREG_LOGPRINTF("echoed %s", szBuffer); 00215 00216 nProcessRet = pclose(POUT); 00217 if (WIFEXITED(nProcessRet)) 00218 { 00219 if (WEXITSTATUS(nProcessRet) == 0) 00220 { 00221 int nLen; 00222 00223 // Normal case 00224 // 00225 // The string as retrieved from wireless.sh 17 (MAC_LENGTH+5+1) characters long. 00226 // e.g 00-16-7c-00-00-00\n 00227 ERREG_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet)); 00228 nLen = strlen(szBuffer); 00229 if (nLen != MAC_LENGTH + 5 + 1) 00230 { 00231 ERREG_ERRORPRINTF("Wrong length [%d] of MAC address [%s]", nLen, szBuffer); 00232 } 00233 else 00234 { 00235 strncpy(mac_address, szBuffer, MAC_LENGTH + 5); 00236 } 00237 } 00238 else 00239 { 00240 ERREG_ERRORPRINTF("pclose returned %d. Error retrieving MAC", WEXITSTATUS(nProcessRet)); 00241 } 00242 } 00243 else 00244 { 00245 ERREG_ERRORPRINTF("pclose did not exit normally"); 00246 } 00247 } 00248 00249 ERREG_LOGPRINTF("return [%s]", mac_address); 00250 return mac_address; 00251 }
const char* get_wlanmactxt_macAddress | ( | void | ) |
Definition at line 255 of file system.c.
00256 { 00257 static char mac_address[MAC_LENGTH + 6] = "00-00-00-00-00-00"; 00258 00259 FILE *fd = fopen(WLAN_MAC_FILE, "r"); 00260 if (fd) 00261 { 00262 // read the content of file into buffer 00263 char* tmp = NULL; 00264 fseek(fd, 0, SEEK_END); 00265 int len = ftell(fd); 00266 00267 tmp = malloc(len+1); 00268 if (tmp) 00269 { 00270 fseek(fd, 0, SEEK_SET); 00271 fread(tmp, sizeof(char), len, fd); 00272 tmp[len] = '\0'; 00273 00274 // strip out the first line, the remained part is mac address 00275 char *new_line = strchr(tmp, '\n'); 00276 if (new_line) 00277 { 00278 snprintf(mac_address, sizeof(mac_address), "%s", new_line+1); 00279 } 00280 00281 free(tmp); 00282 } 00283 00284 fclose(fd); 00285 00286 ERREG_LOGPRINTF("software mac_address [%s]", mac_address); 00287 } 00288 00289 return mac_address; 00290 }