Esempio n. 1
0
void HAL_OTA_Add_System_Info(hal_system_info_t* info, bool create, void* reserved)
{
	const int additional = 2;
	int count = add_system_properties(info, create, additional);
    if (create) {
        info->key_value_count = count + additional;

        CellularDevice device;
        memset(&device, 0, sizeof(device));
        device.size = sizeof(device);
        cellular_device_info(&device, NULL);
        set_key_value(info->key_values+count, "imei", device.imei);
        set_key_value(info->key_values+count+1, "iccid", device.iccid);
    }
}
Esempio n. 2
0
TEE_Result set_spec_key_method(const void *key, size_t kelen)
{
    TEE_Result res;
    TEE_OperationHandle operation;
    uint32_t algorithm   = TEE_ALG_HMAC_MD5;
    uint32_t mode        = TEE_MODE_MAC;
    uint32_t maxKeySize  = 512;
    uint32_t attributeID = TEE_ATTR_SECRET_VALUE;


    res = TEE_AllocateOperation(&operation, algorithm, mode, maxKeySize);
    if(res != TEE_SUCCESS) {
        TEE_Printf("[err] TEE_AllocateOperation\n");
        goto _ret_;
    }

    res = set_key_value(operation->key1, key, kelen, attributeID);
    if(res != TEE_SUCCESS) {
        TEE_Printf("[err] set_key_value\n");
        goto _ret_;
    }

_ret_:

    if (operation) {
        TEE_FreeOperation(operation);   
    }

    return res;
}
Esempio n. 3
0
// 由于使用了strtok()不能用于多线程环境.多线程环境需要修改为strtok_r()
int parse_conf(void *cfgdata,char *conf_str)
{
  char str[CONF_LINE_MAX_LEN+1];
  char section[CONF_LINE_MAX_LEN+1];
  int length;
  char *p;
  char *line;
  cfgdata_t *cd = (cfgdata_t *)cfgdata;

  section[0] = '\0';
  /* if we already have a file loaded, free it first */
  if (valid(cd))
  {
    free_all_the_stuff(cd);
  }

  line = strtok(conf_str, "\n");
  while (line)
  {
    if (strlen(line) <= CONF_LINE_MAX_LEN)
      strcpy(str, line);
    else
      return -1;
    trim(str); /* trim all the blanks or linefeeds(换行) */

    /* skip all comment lines or empty lines */
    if (!str[0] || str[0] == ';' || str[0] == '/' || str[0] == '#')
    {
      line = strtok(NULL, "\n");
      continue;
    }

    length = strlen(str);

    /* check if this is a section line (e.g., [SECTION]) */
    if (str[0] == '[' && str[length - 1] == ']')
    {
      strcpy(section, &str[1]);
      section[length - 2] = 0; /* remove the ] */

      trim(section); /* trim section name after removing [] */
    }
    else
    {
      /* 配置项是名值对,中间用一个或多个空格或垂直制表符间隔 */
      if (((p = strchr(str, '=')) != NULL) || ((p = strchr(str, ' ')) != NULL) || ((p = strchr(str, '\t')) != NULL))
      {
        *(p++) = '\0';
        trim(str); /* str指向key name */
        trim(p);   /* p指向key value */
        set_key_value(cd,section, str, p);
      }
    }

    line = strtok(NULL, "\n");
  }

  return 0;
}
Esempio n. 4
0
int load_conf(void *cfgdata,const char *filename)
{
  FILE *fp;
  char str[CONF_LINE_MAX_LEN*8+1];
  char section[CONF_LINE_MAX_LEN+1];
  int length;
  char *p;
  cfgdata_t *cd = (cfgdata_t *)cfgdata;

  section[0] = '\0';
  fp = fopen(filename, "r");
  if (fp == NULL)
  {
    return -1;
  }

  /* if we already have a file loaded, free it first */
  if (valid(cd))
  {
    free_all_the_stuff(cd);
  }

  while (getconfline(fp,str,CONF_LINE_MAX_LEN*8+1)) // fgets(str, CONF_LINE_MAX_LEN + 1, fp)
  {
    trim(str); /* trim all the blanks or linefeeds(换行) */

    /* skip all comment lines or empty lines */
    if (!str[0] || str[0] == ';' || str[0] == '/' || str[0] == '#')
    {
      continue;
    }

    length = strlen(str);

    /*  check if this is a section line (e.g., [SECTION]) */
    if (str[0] == '[' && str[length - 1] == ']')
    {
      strcpy(section, &str[1]);
      section[length - 2] = 0; /* remove the ] */

      trim(section); /* trim section name after removing [] */
    }
    else
    {
      /* 配置项是名值对,中间用一个或多个空格或垂直制表符间隔 */
      if (((p = strchr(str, ' ')) != NULL) || ((p = strchr(str, '\t')) != NULL) || ((p = strchr(str, '=')) != NULL))
      {
        *(p++) = '\0';
        trim(str); /* str指向key name */
        trim(p);   /* p指向key value */
        set_key_value(cd,section, str, p);
      }
    }
  }

  fclose(fp); /*  load completed; close the file */
  return 0;
}
Esempio n. 5
0
int
pal_set_key_value(char *key, char *value) {

  int ret;
  int i;

  i = 0;
  while(strcmp(key_list[i], LAST_KEY)) {

    if (!strcmp(key, key_list[i])) {
      // Key is valid
      if ((ret = set_key_value(key, value)) < 0) {
        syslog(LOG_ALERT, "pal_set_key_value: set_key_value failed. %d", ret);
        printf("pal_set_key_value: ret = %d\n", ret);
        return ret;
      }
      return ret;
    }
    i++;
  }

  return -1;
}