2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2018-03-15 20:07:17 +01:00
|
|
|
#include "keys.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "cw.h"
|
2018-03-17 12:32:40 +01:00
|
|
|
#include "dbg.h"
|
2022-08-13 09:47:12 +02:00
|
|
|
#include "cfg.h"
|
2018-03-15 20:07:17 +01:00
|
|
|
|
2022-08-17 18:41:17 +02:00
|
|
|
int cw_write_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
|
2018-03-17 12:32:40 +01:00
|
|
|
int subelem_id, const char * parent_key )
|
2018-03-15 20:07:17 +01:00
|
|
|
{
|
|
|
|
char key[256];
|
2022-08-13 09:47:12 +02:00
|
|
|
uint32_t vendor;
|
2022-08-17 18:41:17 +02:00
|
|
|
//bstr16_t version;
|
2022-08-13 09:47:12 +02:00
|
|
|
const char *vendor_s;
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
uint8_t *d;
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2022-08-17 18:41:17 +02:00
|
|
|
|
2018-03-15 20:07:17 +01:00
|
|
|
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
|
|
|
|
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
|
|
|
|
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
|
|
|
|
*/
|
|
|
|
sprintf (key, "%s/%s", parent_key, CW_SKEY_VENDOR);
|
2022-08-17 18:41:17 +02:00
|
|
|
vendor_s = cw_cfg_get_l (cfg_list, key, NULL);
|
2018-03-15 20:07:17 +01:00
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
if (vendor_s == NULL) {
|
2018-04-26 06:50:32 +02:00
|
|
|
cw_log (LOG_ERR, "Can't put subelem %s, no value of type Dword found.", key);
|
2018-03-15 20:07:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2022-08-13 09:47:12 +02:00
|
|
|
|
|
|
|
vendor = atoi(vendor_s);
|
2022-08-17 18:41:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-15 20:07:17 +01:00
|
|
|
sprintf (key, "%s/%s", parent_key, CW_SKEY_VERSION);
|
2022-08-17 18:41:17 +02:00
|
|
|
cw_Val_t * val = cw_cfg_get_val_l(cfg_list, key, CW_TYPE_BSTR16);
|
|
|
|
|
|
|
|
//version = cw_cfg_get_bstr16 (cfg, key, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (val == NULL) {
|
2018-04-26 06:50:32 +02:00
|
|
|
cw_log (LOG_ERR, "Can't put subelem %s, no value of type Bstr16 found.", key);
|
2018-03-15 20:07:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = dst;
|
|
|
|
|
|
|
|
/* put vendor */
|
2022-08-13 09:47:12 +02:00
|
|
|
d += cw_put_dword(d, vendor); //->type->put (vendor, d);
|
2018-03-15 20:07:17 +01:00
|
|
|
|
|
|
|
/* put version */
|
|
|
|
|
2022-08-17 18:41:17 +02:00
|
|
|
d += cw_put_dword (d, (subelem_id << 16) | val->type->len(val));
|
|
|
|
// d += cw_put_bstr16(d, version);
|
|
|
|
d += val->type->put(val,d);
|
|
|
|
|
|
|
|
cw_val_destroy(val);
|
2022-08-13 09:47:12 +02:00
|
|
|
|
2022-08-17 18:41:17 +02:00
|
|
|
// free(version);
|
2018-03-15 20:07:17 +01:00
|
|
|
|
|
|
|
return d-dst;
|
|
|
|
}
|