3939#include "libmtp.h"
4040
4141#define GARMIN_VENDOR 0x091E
42- #define DESCENT_MK2 0x4CBA
43- #define DESCENT_MK2_APAC 0x4E76
42+
43+ #define DESCENT_MK2 3258
4444
4545// deal with ancient libmpt found on older Linux distros
4646#ifndef LIBMTP_FILES_AND_FOLDERS_ROOT
@@ -59,6 +59,24 @@ typedef struct garmin_device_t {
5959#endif
6060} garmin_device_t ;
6161
62+ // Ids can be found at https://developer.garmin.com/connect-iq/reference-guides/devices-reference/
63+ // (look for 'Part Number')
64+
65+ const garmin_model_t garmin_models [] = {
66+ { "Descent™ G1 / G1 Solar" , 4005 , true },
67+ { "Descent™ G2" , 4588 , true },
68+ { "Descent™ Mk1" , 2859 , false },
69+ { "Descent™ Mk1 APAC" , 2991 , false },
70+ { "Descent™ Mk2(i)" , 3258 , true },
71+ { "Descent™ Mk2(i) APAC" , 3702 , true },
72+ { "Descent™ Mk2 S" , 3542 , true },
73+ { "Descent™ Mk2 S APAC" , 3930 , true },
74+ { "Descent™ Mk3(i) 43mm" , 4222 , true },
75+ { "Descent™ Mk3(i) 51mm" , 4223 , true },
76+ { "Descent™ X50i" , 4518 , true },
77+ { NULL , 0 , false }
78+ };
79+
6280static dc_status_t garmin_device_set_fingerprint (dc_device_t * abstract , const unsigned char data [], unsigned int size );
6381static dc_status_t garmin_device_foreach (dc_device_t * abstract , dc_dive_callback_t callback , void * userdata );
6482static dc_status_t garmin_device_close (dc_device_t * abstract );
@@ -99,7 +117,7 @@ garmin_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *ios
99117 // for a Descent Mk2/Mk2i, we have to use MTP to access its storage;
100118 // for Garmin devices, the model number corresponds to the lower three nibbles of the USB product ID
101119 // in order to have only one entry for the Mk2, we don't use the Mk2/APAC model number in our code
102- device -> use_mtp = ( model == ( 0x0FFF & DESCENT_MK2 )) ;
120+ device -> use_mtp = model == DESCENT_MK2 ;
103121 device -> mtp_device = NULL ;
104122#endif
105123
@@ -335,7 +353,17 @@ mtp_get_file_list(dc_device_t *abstract, struct file_list *files)
335353 rawdevices [i ].device_entry .vendor_id , rawdevices [i ].device_entry .product_id );
336354 continue ;
337355 }
338- if (rawdevices [i ].device_entry .product_id != DESCENT_MK2 && rawdevices [i ].device_entry .product_id != DESCENT_MK2_APAC ) {
356+
357+ bool mtp_capable = false;
358+ for (unsigned j = 0 ; garmin_models [j ].name ; j ++ ) {
359+ if ((garmin_models [j ].id | 0x4000 ) == rawdevices [i ].device_entry .product_id ) {
360+ mtp_capable = garmin_models [j ].mtp_capable ;
361+
362+ break ;
363+ }
364+ }
365+
366+ if (!mtp_capable ) {
339367 DEBUG (abstract -> context , "Garmin/mtp: skipping Garmin raw device %04x/%04x, as it is not a dive computer / does not support MTP" ,
340368 rawdevices [i ].device_entry .vendor_id , rawdevices [i ].device_entry .product_id );
341369 continue ;
0 commit comments