@@ -461,6 +461,8 @@ def _process_data_phase(self, data):
461
461
462
462
def _cmd_get_device_info (self ):
463
463
"""Handle GetDeviceInfo command."""
464
+ print ("[MTP] Generating device info response" )
465
+
464
466
# Prepare the device info dataset
465
467
data = bytearray (512 ) # Pre-allocate buffer
466
468
offset = 0
@@ -470,15 +472,22 @@ def _cmd_get_device_info(self):
470
472
offset += 2
471
473
472
474
# MTP vendor extension ID
473
- struct .pack_into ("<I" , data , offset , 0x00000000 ) # No vendor extension
475
+ # Use Microsoft's extension ID to better identify as a true MTP device
476
+ struct .pack_into ("<I" , data , offset , 0x00000006 ) # Microsoft MTP Extension
474
477
offset += 4
475
478
476
479
# MTP version
477
480
struct .pack_into ("<H" , data , offset , 100 ) # Version 1.00
478
481
offset += 2
479
482
480
- # MTP extensions (empty string)
481
- struct .pack_into ("<H" , data , offset , 0 ) # No extension string
483
+ # MTP extensions description string
484
+ ext_string = "microsoft.com: 1.0" # Standard Microsoft extension string
485
+ struct .pack_into ("<H" , data , offset , len (ext_string ) + 1 ) # String length including null terminator
486
+ offset += 2
487
+ for c in ext_string :
488
+ struct .pack_into ("<H" , data , offset , ord (c ))
489
+ offset += 2
490
+ struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
482
491
offset += 2
483
492
484
493
# Functional mode
@@ -530,12 +539,18 @@ def _cmd_get_device_info(self):
530
539
struct .pack_into ("<H" , data , offset , fmt )
531
540
offset += 2
532
541
533
- # Manufacturer (empty string)
534
- struct .pack_into ("<H" , data , offset , 0 )
542
+ # Manufacturer
543
+ manufacturer = "MicroPython"
544
+ struct .pack_into ("<H" , data , offset , len (manufacturer ) + 1 )
545
+ offset += 2
546
+ for c in manufacturer :
547
+ struct .pack_into ("<H" , data , offset , ord (c ))
548
+ offset += 2
549
+ struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
535
550
offset += 2
536
551
537
- # Model (MicroPython)
538
- model = "MicroPython"
552
+ # Model
553
+ model = "MicroPython MTP Device "
539
554
struct .pack_into ("<H" , data , offset , len (model ) + 1 )
540
555
offset += 2
541
556
for c in model :
@@ -544,12 +559,24 @@ def _cmd_get_device_info(self):
544
559
struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
545
560
offset += 2
546
561
547
- # Device version (empty string)
548
- struct .pack_into ("<H" , data , offset , 0 )
562
+ # Device version
563
+ version = "1.0"
564
+ struct .pack_into ("<H" , data , offset , len (version ) + 1 )
565
+ offset += 2
566
+ for c in version :
567
+ struct .pack_into ("<H" , data , offset , ord (c ))
568
+ offset += 2
569
+ struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
549
570
offset += 2
550
571
551
- # Serial number (empty string)
552
- struct .pack_into ("<H" , data , offset , 0 )
572
+ # Serial number
573
+ serial = "MP12345" # Generic serial number
574
+ struct .pack_into ("<H" , data , offset , len (serial ) + 1 )
575
+ offset += 2
576
+ for c in serial :
577
+ struct .pack_into ("<H" , data , offset , ord (c ))
578
+ offset += 2
579
+ struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
553
580
offset += 2
554
581
555
582
# Send the device info
@@ -603,7 +630,10 @@ def _cmd_get_storage_ids(self):
603
630
604
631
def _cmd_get_storage_info (self , params ):
605
632
"""Handle GetStorageInfo command."""
633
+ print ("[MTP] Generating storage info for storage ID: 0x{:08x}" .format (params [0 ] if params else 0 ))
634
+
606
635
if not params or params [0 ] != self ._storage_id :
636
+ print ("[MTP] Invalid storage ID requested: 0x{:08x}" .format (params [0 ] if params else 0 ))
607
637
self ._send_response (_MTP_RESPONSE_INVALID_STORAGE_ID )
608
638
return
609
639
@@ -612,8 +642,10 @@ def _cmd_get_storage_info(self, params):
612
642
fs_stat = os .statvfs (self ._storage_path )
613
643
free_bytes = fs_stat [0 ] * fs_stat [4 ] # f_bsize * f_bavail
614
644
total_bytes = fs_stat [0 ] * fs_stat [2 ] # f_bsize * f_blocks
615
- except :
645
+ print ("[MTP] Storage stats: total={} bytes, free={} bytes" .format (total_bytes , free_bytes ))
646
+ except Exception as e :
616
647
# If we can't get stats, just return reasonable defaults
648
+ print ("[MTP] Error getting storage stats: {}" .format (str (e )))
617
649
free_bytes = 1024 * 1024 # 1MB
618
650
total_bytes = 4 * 1024 * 1024 # 4MB
619
651
@@ -645,12 +677,18 @@ def _cmd_get_storage_info(self, params):
645
677
struct .pack_into ("<I" , data , offset , 0xFFFFFFFF )
646
678
offset += 4
647
679
648
- # Storage description (empty)
649
- struct .pack_into ("<H" , data , offset , 0 )
680
+ # Storage description
681
+ desc = "MicroPython Flash Storage"
682
+ struct .pack_into ("<H" , data , offset , len (desc ) + 1 )
683
+ offset += 2
684
+ for c in desc :
685
+ struct .pack_into ("<H" , data , offset , ord (c ))
686
+ offset += 2
687
+ struct .pack_into ("<H" , data , offset , 0 ) # Null terminator
650
688
offset += 2
651
689
652
690
# Volume identifier (root)
653
- volume_id = "MicroPython"
691
+ volume_id = "MicroPython Storage "
654
692
struct .pack_into ("<H" , data , offset , len (volume_id ) + 1 )
655
693
offset += 2
656
694
for c in volume_id :
0 commit comments