@@ -205,6 +205,31 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
205
205
return ret ;
206
206
}
207
207
208
+ static int hidpp_send_rap_command_sync (struct hidpp_device * hidpp_dev ,
209
+ u8 report_id , u8 sub_id , u8 reg_address , u8 * params , int param_count ,
210
+ struct hidpp_report * response )
211
+ {
212
+ struct hidpp_report * message = kzalloc (sizeof (struct hidpp_report ),
213
+ GFP_KERNEL );
214
+ int ret ;
215
+
216
+ if ((report_id != REPORT_ID_HIDPP_SHORT ) &&
217
+ (report_id != REPORT_ID_HIDPP_LONG ))
218
+ return - EINVAL ;
219
+
220
+ if (param_count > sizeof (message -> rap .params ))
221
+ return - EINVAL ;
222
+
223
+ message -> report_id = report_id ;
224
+ message -> rap .sub_id = sub_id ;
225
+ message -> rap .reg_address = reg_address ;
226
+ memcpy (& message -> rap .params , params , param_count );
227
+
228
+ ret = hidpp_send_message_sync (hidpp_dev , message , response );
229
+ kfree (message );
230
+ return ret ;
231
+ }
232
+
208
233
static inline bool hidpp_match_answer (struct hidpp_report * question ,
209
234
struct hidpp_report * answer )
210
235
{
@@ -220,6 +245,45 @@ static inline bool hidpp_match_error(struct hidpp_report *question,
220
245
(answer -> fap .params [0 ] == question -> fap .funcindex_clientid );
221
246
}
222
247
248
+ /* -------------------------------------------------------------------------- */
249
+ /* HIDP++ 1.0 commands */
250
+ /* -------------------------------------------------------------------------- */
251
+
252
+ #define HIDPP_SET_REGISTER 0x80
253
+ #define HIDPP_GET_REGISTER 0x81
254
+ #define HIDPP_SET_LONG_REGISTER 0x82
255
+ #define HIDPP_GET_LONG_REGISTER 0x83
256
+
257
+ #define HIDPP_REG_PAIRING_INFORMATION 0xB5
258
+ #define DEVICE_NAME 0x40
259
+
260
+ static char * hidpp_get_unifying_name (struct hidpp_device * hidpp_dev )
261
+ {
262
+ struct hidpp_report response ;
263
+ int ret ;
264
+ /* hid-logitech-dj is in charge of setting the right device index */
265
+ u8 params [1 ] = { DEVICE_NAME };
266
+ char * name ;
267
+ int len ;
268
+
269
+ ret = hidpp_send_rap_command_sync (hidpp_dev ,
270
+ REPORT_ID_HIDPP_SHORT ,
271
+ HIDPP_GET_LONG_REGISTER ,
272
+ HIDPP_REG_PAIRING_INFORMATION ,
273
+ params , 1 , & response );
274
+ if (ret )
275
+ return NULL ;
276
+
277
+ len = response .rap .params [1 ];
278
+
279
+ name = kzalloc (len + 1 , GFP_KERNEL );
280
+ if (!name )
281
+ return NULL ;
282
+
283
+ memcpy (name , & response .rap .params [2 ], len );
284
+ return name ;
285
+ }
286
+
223
287
/* -------------------------------------------------------------------------- */
224
288
/* 0x0000: Root */
225
289
/* -------------------------------------------------------------------------- */
@@ -726,13 +790,21 @@ static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
726
790
return 0 ;
727
791
}
728
792
729
- static void hidpp_overwrite_name (struct hid_device * hdev )
793
+ static void hidpp_overwrite_name (struct hid_device * hdev , bool use_unifying )
730
794
{
731
795
struct hidpp_device * hidpp = hid_get_drvdata (hdev );
732
796
char * name ;
733
797
u8 name_length ;
734
798
735
- name = hidpp_get_device_name (hidpp , & name_length );
799
+ if (use_unifying )
800
+ /*
801
+ * the device is connected through an Unifying receiver, and
802
+ * might not be already connected.
803
+ * Ask the receiver for its name.
804
+ */
805
+ name = hidpp_get_unifying_name (hidpp );
806
+ else
807
+ name = hidpp_get_device_name (hidpp , & name_length );
736
808
737
809
if (!name )
738
810
hid_err (hdev , "unable to retrieve the name of the device" );
@@ -783,12 +855,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
783
855
goto hid_parse_fail ;
784
856
}
785
857
786
- /* the device is connected, we can ask for its name */
787
858
hid_info (hdev , "HID++ %u.%u device connected.\n" ,
788
859
hidpp -> protocol_major , hidpp -> protocol_minor );
789
- hidpp_overwrite_name (hdev );
790
860
}
791
861
862
+ hidpp_overwrite_name (hdev , id -> group == HID_GROUP_LOGITECH_DJ_DEVICE );
863
+
792
864
if (hidpp -> quirks & HIDPP_QUIRK_CLASS_WTP ) {
793
865
ret = wtp_get_config (hidpp );
794
866
if (ret )
0 commit comments