![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: io/DeviceMemory.cpp
- Revision:
- 67:c360a2b2c948
- Child:
- 68:0dc778a16d0d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/io/DeviceMemory.cpp Sun Nov 30 19:34:49 2014 +0000 @@ -0,0 +1,39 @@ +#include "DeviceMemory.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS" + +DeviceMemory::DeviceMemory(MDMSerial& mdm) : + _mdm(mdm) +{ +} + +bool DeviceMemory::loadPlatformCredentials(char *username, char *password, size_t len) +{ + char buffer[len*2+3]; int res, len2; + + if ((res = _mdm.readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer))) < 0) + return false; + + buffer[(size_t)res] = '\0'; + sscanf(buffer, "%s\n%s\n%n", username, password, &len2); + return res == len2; +} + +bool DeviceMemory::savePlatformCredentials(char *username, char *password, size_t len) +{ + char buffer[len*2+3]; int res; + + res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password); + if ((res < 0) || (res >= sizeof(buffer))) + return false; + + return res == _mdm.writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res); +} + +bool DeviceMemory::resetPlatformCredentials() +{ + return _mdm.delFile(PLATFORM_CREDENTIALS_FILE); +}