summaryrefslogtreecommitdiff
path: root/cleopatre/application
diff options
context:
space:
mode:
authorCeline Buret2011-08-04 11:12:00 +0200
committerCeline Buret2011-08-05 16:03:00 +0200
commitacceef214051109c1854bd3ed6cfdf4644570856 (patch)
tree7c39fbb2d342d4d245d9eab0114c07748be66eb9 /cleopatre/application
parentb5a86f9c277c3600e47d0d5b01ab3357f0bde14b (diff)
cleo/{app,devkit/tests}: implement current index of vs_get_version.cnf, closes #976
Changes in libspid: * implement a new function to get the image position of the given MTD path, * update unitary tests: * test the new function, * solve a memory leak in setup() function, * remove dead code, * correctly rename the test suite as "image" instead of "system", * comment tests leading to following error that made the test not runnable: "check_pack.c:269: Error in call to write: Bad file descriptor". Changes in managerd: * call the new libspid function to fill vs_mme_get_version.cnf field returning the index of the current image, * solve 2 compilation warnings in vs_mme_get_version() function.
Diffstat (limited to 'cleopatre/application')
-rw-r--r--cleopatre/application/libspid/inc/libspid.h2
-rw-r--r--cleopatre/application/libspid/src/image.c67
-rw-r--r--cleopatre/application/managerd/src/vs_mme.c11
3 files changed, 76 insertions, 4 deletions
diff --git a/cleopatre/application/libspid/inc/libspid.h b/cleopatre/application/libspid/inc/libspid.h
index 5e505cbe72..05ad748da8 100644
--- a/cleopatre/application/libspid/inc/libspid.h
+++ b/cleopatre/application/libspid/inc/libspid.h
@@ -142,6 +142,8 @@ extern libspid_error_t libspid_mac_bin_to_str(const unsigned char *bin, char *st
extern libspid_error_t libspid_hexstring_to_binary (const char* hex_string, unsigned char *binary, unsigned int binary_length);
extern libspid_error_t libspid_binary_to_hexstring (const unsigned char *binary, unsigned int binary_length, char *hex_string);
extern libspid_error_t libspid_image_get_desc(libspid_image_desc_type_t type, spidcom_image_desc_t *image_desc, char *mtd_name);
+extern libspid_error_t
+libspid_image_get_index (const char *mtd_path, int *index);
extern libspid_error_t libspid_image_select(libspid_image_select_t select);
extern libspid_error_t libspid_network_get_ip (const char *interface, libspid_ip_t *ip);
extern libspid_error_t libspid_network_set_ip (const char *interface, const libspid_ip_t *ip);
diff --git a/cleopatre/application/libspid/src/image.c b/cleopatre/application/libspid/src/image.c
index 2019214b7c..6a3fd9051d 100644
--- a/cleopatre/application/libspid/src/image.c
+++ b/cleopatre/application/libspid/src/image.c
@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <libgen.h>
#ifndef __UTESTS__
#include <mtd/mtd-user.h>
#endif /* __UTESTS__ */
@@ -202,6 +203,72 @@ libspid_error_t libspid_image_get_desc(libspid_image_desc_type_t type, spidcom_i
}
/**
+ * Get index of an image from its MTD partition.
+ *
+ * \param mtd_path Full path of MTD partition
+ of the image for which index is wanted
+ * \param index index to return, set to -1 if not found
+ * \return error type (LIBSPID_SUCCESS if success)
+ * \return LIBSPID_ERROR_PARAM: bad input parameters
+ * \return LIBSPID_ERROR_NOT_FOUND: index not found
+ * \return LIBSPID_ERROR_SYSTEM: system error, see errno
+ */
+libspid_error_t
+libspid_image_get_index (const char *mtd_path, int *index)
+{
+ FILE *fp = NULL;
+ char *mtd_partition = NULL;
+ char mtd_path_tmp[32] = {0};
+ char line_buffer[LIBSPID_CONFIG_LINE_MAX_LEN] = {0};
+ int dummy;
+
+ /* Check arguments */
+ if ((NULL == mtd_path) || (NULL == index))
+ {
+ return LIBSPID_ERROR_PARAM;
+ }
+
+ /* Copy mtd_path not to modify it */
+ memcpy (mtd_path_tmp, mtd_path, sizeof (mtd_path_tmp));
+
+ /* Initialize index as not found */
+ *index = -1;
+
+ /* From full MTD path, get the MTD partition */
+ mtd_partition = basename (mtd_path_tmp);
+
+ /* From MTD partition, find the MTD name in file "/proc/mtd" */
+ if ((fp = fopen (LIBSPID_SYSTEM_MTD_PATH, "r")) == NULL)
+ {
+ return LIBSPID_ERROR_SYSTEM;
+ }
+ while (fgets (line_buffer, LIBSPID_CONFIG_LINE_MAX_LEN - 1, fp) != NULL)
+ {
+ if (strstr (line_buffer, mtd_partition) != NULL)
+ {
+ /* Extract MTD name from line mtd<num>: <size> <erasesize> "name"
+ * We search following name : "image <index>" */
+ if (4 != sscanf (line_buffer, "mtd%d: %08x %08x \"image %d\"",
+ &dummy, &dummy, &dummy, index))
+ {
+ fclose (fp);
+ return LIBSPID_ERROR_NOT_FOUND;
+ }
+ break;
+ }
+ }
+ fclose (fp);
+
+ /* Check if index has been found */
+ if (-1 == *index)
+ {
+ return LIBSPID_ERROR_NOT_FOUND;
+ }
+
+ return LIBSPID_SUCCESS;
+}
+
+/**
* Select the current image firmware to boot on the next time.
*
* \param select the image to select for nrxt boot
diff --git a/cleopatre/application/managerd/src/vs_mme.c b/cleopatre/application/managerd/src/vs_mme.c
index 71ded24256..45070d8be1 100644
--- a/cleopatre/application/managerd/src/vs_mme.c
+++ b/cleopatre/application/managerd/src/vs_mme.c
@@ -57,6 +57,7 @@ enum bridge_status vs_mme_get_version (struct managerd_ctx *ctx, MME_t *request,
FILE *fp;
char tmp_buffer[256];
char label[64], version[64];
+ int index;
assert (NULL != ctx);
assert (NULL != request);
@@ -77,8 +78,6 @@ enum bridge_status vs_mme_get_version (struct managerd_ctx *ctx, MME_t *request,
memcpy (get_version_cnf->oui, OUI_SPIDCOM, 3);
get_version_cnf->result = 0;
get_version_cnf->device_id = SPC300_ID;
- // TODO: find the right index value
- get_version_cnf->current_image_index = 0;
/* get current image version */
memset (&desc, '\0', sizeof (desc));
@@ -90,6 +89,10 @@ enum bridge_status vs_mme_get_version (struct managerd_ctx *ctx, MME_t *request,
sizeof (desc.version));
}
+ /* Retrieve index of current image from MTD path */
+ libspid_image_get_index ((const char *) mtd_name, &index);
+ get_version_cnf->current_image_index = (unsigned char) index;
+
if ((fp = fopen (PLC_VERSION_PATH, "r")) != NULL)
{
while (fgets (tmp_buffer, 256, fp))
@@ -116,9 +119,9 @@ enum bridge_status vs_mme_get_version (struct managerd_ctx *ctx, MME_t *request,
memcpy (get_version_cnf->applicative_alternate, desc.version,
sizeof (desc.version));
}
- if (strlen (get_version_cnf->applicative_alternate) == 0)
+ if (strlen ((char *) get_version_cnf->applicative_alternate) == 0)
{
- strcpy (get_version_cnf->applicative_alternate, "none");
+ strcpy ((char *) get_version_cnf->applicative_alternate, "none");
}
/* send confirm MME */