-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to get device serial from system BIOS table #258
Changes from all commits
b7d0ab7
f40c225
fd0ac5e
175386a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
#include "freertos/task.h" | ||
#endif | ||
|
||
#ifndef MAX_DEV_SERIAL_SZ | ||
#define MAX_DEV_SERIAL_SZ 255 | ||
#endif | ||
|
||
bool file_exists(char const *filename) | ||
{ | ||
FILE *fp = NULL; | ||
|
@@ -317,3 +321,58 @@ int print_timestamp(void) | |
#endif | ||
return 0; | ||
} | ||
|
||
#if defined(GET_DEV_SERIAL) | ||
// Get device serial number | ||
int get_device_serial(char *serial_buff) | ||
{ | ||
FILE *fp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do input check for serial_buff before using it. Do it every place |
||
char *cmd = "dmidecode -s system-serial-number"; | ||
int out_sz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add const for cmd variable ..As this value wouldnt change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check other places also |
||
char out[MAX_DEV_SERIAL_SZ]; | ||
int results_sz = 0; | ||
int ret = -1; | ||
char *results = (char *)malloc(MAX_DEV_SERIAL_SZ * sizeof(char)); | ||
|
||
if (cmd != NULL) { | ||
/* Open the command for reading. */ | ||
fp = popen(cmd, "r"); | ||
if (fp != NULL) { | ||
|
||
/* Read the output a line at a time - output it. */ | ||
while (fgets(out, out_sz = sizeof(out), fp) != NULL) { | ||
if (strcat_s(results, MAX_DEV_SERIAL_SZ, out) != | ||
0) { | ||
LOG(LOG_ERROR, "Strcat() failed!\n"); | ||
goto end; | ||
} | ||
} | ||
|
||
results_sz = strnlen_s(results, MAX_DEV_SERIAL_SZ); | ||
if (!results_sz) { | ||
goto end; | ||
} | ||
|
||
if (memcpy_s(serial_buff, results_sz, results, | ||
results_sz)) { | ||
LOG(LOG_ERROR, | ||
"Failed to copy device serial contents\n"); | ||
goto end; | ||
} | ||
} else { | ||
goto end; | ||
} | ||
ret = 0; | ||
} | ||
end: | ||
/* close */ | ||
if (fp) { | ||
pclose(fp); | ||
} | ||
if (results) { | ||
free(results); | ||
results = NULL; | ||
} | ||
return ret; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO-DO: make it const