diff options
| author | hathach <[email protected]> | 2025-09-20 00:42:06 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2025-09-20 00:42:06 +0700 |
| commit | b70804b0c4212f67625e945986b91bbe1d965059 (patch) | |
| tree | 42d1c5a15589ffbefb202d9ecde624493c28b7ff /src | |
| parent | 57c5e5516a7e6711085e3d5f57d2023d6ce1b237 (diff) | |
implement get device properties value
Diffstat (limited to 'src')
| -rw-r--r-- | src/class/mtp/mtp.h | 38 | ||||
| -rw-r--r-- | src/class/mtp/mtp_device.c | 11 |
2 files changed, 38 insertions, 11 deletions
diff --git a/src/class/mtp/mtp.h b/src/class/mtp/mtp.h index c48a2469c..138cb1b86 100644 --- a/src/class/mtp/mtp.h +++ b/src/class/mtp/mtp.h @@ -782,17 +782,30 @@ typedef struct TU_ATTR_PACKED { // - datetime_wstring date_modified; // - wstring keywords; -// DevicePropDesc Dataset +// Device property desc up to get/set typedef struct TU_ATTR_PACKED { uint16_t device_property_code; uint16_t datatype; uint8_t get_set; -} mtp_device_prop_desc_t; +} mtp_device_prop_desc_header_t; + // The following fields will be dynamically added to the struct at runtime: // - wstring factory_def_value; // - wstring current_value_len; // - uint8_t form_flag; +// no form +#define MTP_DEVICE_PROPERTIES_TYPEDEF(_type) \ + struct TU_ATTR_PACKED { \ + uint16_t device_property_code; \ + uint16_t datatype; \ + uint8_t get_set; \ + _type factory_default; \ + _type current_value; \ + uint8_t form_flag; /* 0: none, 1: range, 2: enum */ \ + }; + + typedef struct TU_ATTR_PACKED { uint16_t wLength; uint16_t code; @@ -832,15 +845,28 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_field(mtp_generic } TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_string(mtp_generic_container_t* p_container, uint8_t count, uint16_t* utf16) { - const uint32_t prev_len = p_container->len; uint8_t* container8 = (uint8_t*) p_container; - *(container8 + p_container->len) = count; - p_container->len += 1; + container8[p_container->len] = count; + p_container->len++; memcpy(container8 + p_container->len, utf16, 2 * count); p_container->len += 2 * count; - return p_container->len - prev_len; + return 1 + 2 * count; +} + +TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_cstring(mtp_generic_container_t* p_container, const char* str) { + uint8_t* container8 = (uint8_t*) p_container; + const uint8_t len = (uint8_t) (strlen(str) + 1); // include null + container8[p_container->len] = len; + p_container->len++; + + for (uint8_t i = 0; i < len; i++) { + container8[p_container->len] = str[i]; + container8[p_container->len + 1] = 0; + p_container->len += 2; + } + return 1 + 2 * len; } TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_uint8(mtp_generic_container_t* p_container, uint8_t data) { diff --git a/src/class/mtp/mtp_device.c b/src/class/mtp/mtp_device.c index d0a1d6c40..2e9ac9a92 100644 --- a/src/class/mtp/mtp_device.c +++ b/src/class/mtp/mtp_device.c @@ -466,11 +466,12 @@ mtp_phase_type_t mtpd_handle_cmd(mtpd_interface_t* p_mtp) { case MTP_OP_GET_DEVICE_PROP_DESC: TU_LOG_DRV(" MTP command: MTP_OP_GET_DEVICE_PROP_DESC\n"); - return mtpd_handle_cmd_get_device_prop_desc(); + break; case MTP_OP_GET_DEVICE_PROP_VALUE: TU_LOG_DRV(" MTP command: MTP_OP_GET_DEVICE_PROP_VALUE\n"); - return mtpd_handle_cmd_get_device_prop_value(); + break; + case MTP_OP_SEND_OBJECT_INFO: TU_LOG_DRV(" MTP command: MTP_OP_SEND_OBJECT_INFO\n"); return mtpd_handle_cmd_send_object_info(); @@ -673,11 +674,11 @@ mtp_phase_type_t mtpd_handle_cmd_get_device_prop_desc(void) { case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME: { - TU_VERIFY_STATIC(sizeof(mtp_device_prop_desc_t) < MTP_MAX_PACKET_SIZE, "mtp_device_info_t shall fit in MTP_MAX_PACKET_SIZE"); + TU_VERIFY_STATIC(sizeof(mtp_device_prop_desc_header_t) < MTP_MAX_PACKET_SIZE, "mtp_device_info_t shall fit in MTP_MAX_PACKET_SIZE"); p_container->type = MTP_CONTAINER_TYPE_DATA_BLOCK; p_container->code = MTP_OP_GET_DEVICE_PROP_DESC; - p_container->len = MTP_CONTAINER_HEADER_LENGTH + sizeof(mtp_device_prop_desc_t); - mtp_device_prop_desc_t *d = (mtp_device_prop_desc_t *)p_container->data; + p_container->len = MTP_CONTAINER_HEADER_LENGTH + sizeof(mtp_device_prop_desc_header_t); + mtp_device_prop_desc_header_t *d = (mtp_device_prop_desc_header_t *)p_container->data; d->device_property_code = (uint16_t)(device_prop_code); d->datatype = MTP_DATA_TYPE_STR; d->get_set = MTP_MODE_GET; |
