From d9c6dfbe2b2ede8c4147cef2f82765a16ec803b7 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 20 Sep 2025 17:37:47 +0700 Subject: [PATCH] implement get device properties describer and device properties value --- examples/device/mtp/src/mtp_fs_example.c | 29 +++++++++-- src/class/mtp/mtp_device.c | 64 ------------------------ 2 files changed, 26 insertions(+), 67 deletions(-) diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c index 89814fb8f..e0dafb5ab 100644 --- a/examples/device/mtp/src/mtp_fs_example.c +++ b/examples/device/mtp/src/mtp_fs_example.c @@ -216,6 +216,26 @@ int32_t tud_mtp_command_received_cb(uint8_t idx, mtp_generic_container_t* cmd_bl break; } + case MTP_OP_GET_DEVICE_PROP_DESC: { + const uint16_t dev_prop_code = (uint16_t) cmd_block->data[0]; + mtp_device_prop_desc_header_t device_prop_header; + device_prop_header.device_property_code = dev_prop_code; + switch (dev_prop_code) { + case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME: + device_prop_header.datatype = MTP_DATA_TYPE_STR; + device_prop_header.get_set = MTP_MODE_GET; + mtp_container_add_raw(out_block, &device_prop_header, sizeof(device_prop_header)); + mtp_container_add_cstring(out_block, DEV_PROP_FRIENDLY_NAME); // factory + mtp_container_add_cstring(out_block, DEV_PROP_FRIENDLY_NAME); // current + mtp_container_add_uint8(out_block, 0); // no form + tud_mtp_data_send(out_block); + break; + + default: return MTP_RESP_PARAMETER_NOT_SUPPORTED; + } + break; + } + case MTP_OP_GET_DEVICE_PROP_VALUE: { const uint16_t dev_prop_code = (uint16_t) cmd_block->data[0]; switch (dev_prop_code) { @@ -224,16 +244,19 @@ int32_t tud_mtp_command_received_cb(uint8_t idx, mtp_generic_container_t* cmd_bl tud_mtp_data_send(out_block); break; - default: return -1; + default: return MTP_RESP_PARAMETER_NOT_SUPPORTED; } break; } + case MTP_OP_GET_OBJECT_HANDLES: - default: return -1; + break; + + default: return MTP_RESP_OPERATION_NOT_SUPPORTED; } - return 0; + return MTP_RESP_OK; } //--------------------------------------------------------------------+ diff --git a/src/class/mtp/mtp_device.c b/src/class/mtp/mtp_device.c index 2e9ac9a92..cb7bb9574 100644 --- a/src/class/mtp/mtp_device.c +++ b/src/class/mtp/mtp_device.c @@ -90,8 +90,6 @@ static mtp_phase_type_t mtpd_handle_cmd_get_object_info(void); static mtp_phase_type_t mtpd_handle_cmd_get_object(void); static mtp_phase_type_t mtpd_handle_dti_get_object(void); static mtp_phase_type_t mtpd_handle_cmd_delete_object(void); -static mtp_phase_type_t mtpd_handle_cmd_get_device_prop_desc(void); -static mtp_phase_type_t mtpd_handle_cmd_get_device_prop_value(void); static mtp_phase_type_t mtpd_handle_cmd_send_object_info(void); static mtp_phase_type_t mtpd_handle_dto_send_object_info(void); static mtp_phase_type_t mtpd_handle_cmd_send_object(void); @@ -662,68 +660,6 @@ mtp_phase_type_t mtpd_handle_cmd_delete_object(void) return MTP_PHASE_RESPONSE; } -mtp_phase_type_t mtpd_handle_cmd_get_device_prop_desc(void) -{ - mtp_generic_container_t* p_container = &_mtpd_epbuf.container; - uint32_t device_prop_code = p_container->data[0]; - - mtp_phase_type_t rt; - if ((rt = mtpd_chk_session_open(__func__)) != MTP_PHASE_NONE) return rt; - - switch(device_prop_code) - { - case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME: - { - 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_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; - mtpd_gct_append_wstring(CFG_TUD_MODEL); // factory_def_value - mtpd_gct_append_wstring(CFG_TUD_MODEL); // current_value_len - mtpd_gct_append_uint8(0x00); // form_flag - _mtpd_itf.queued_len = p_container->len; - return MTP_PHASE_DATA_IN; - } - default: - break; - } - - p_container->type = MTP_CONTAINER_TYPE_RESPONSE_BLOCK; - p_container->code = MTP_RESP_PARAMETER_NOT_SUPPORTED; - p_container->len = MTP_CONTAINER_HEADER_LENGTH; - return MTP_PHASE_RESPONSE; -} - -mtp_phase_type_t mtpd_handle_cmd_get_device_prop_value(void) -{ - mtp_generic_container_t* p_container = &_mtpd_epbuf.container; - uint32_t device_prop_code = p_container->data[0]; - - mtp_phase_type_t rt; - if ((rt = mtpd_chk_session_open(__func__)) != MTP_PHASE_NONE) return rt; - - p_container->len = MTP_CONTAINER_HEADER_LENGTH; - p_container->type = MTP_CONTAINER_TYPE_DATA_BLOCK; - p_container->code = MTP_OP_GET_DEVICE_PROP_VALUE; - - switch(device_prop_code) - { - // TODO support more device properties - case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME: - mtpd_gct_append_wstring(CFG_TUD_MODEL); - _mtpd_itf.queued_len = p_container->len; - return MTP_PHASE_DATA_IN; - default: - p_container->type = MTP_CONTAINER_TYPE_RESPONSE_BLOCK; - p_container->code = MTP_RESP_PARAMETER_NOT_SUPPORTED; - return MTP_PHASE_RESPONSE; - } -} - mtp_phase_type_t mtpd_handle_cmd_send_object_info(void) { mtp_generic_container_t* p_container = &_mtpd_epbuf.container;