1/* $FreeBSD: head/sys/dev/usb/template/usb_template_mtp.c 246123 2013-01-30 15:46:26Z hselasky $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky <hselasky@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright --- 45 unchanged lines hidden (view full) --- 55#include <sys/sx.h> 56#include <sys/unistd.h> 57#include <sys/callout.h> 58#include <sys/malloc.h> 59#include <sys/priv.h> 60 61#include <dev/usb/usb.h> 62#include <dev/usb/usbdi.h> |
63#include <dev/usb/usb_core.h> 64 |
65#include <dev/usb/template/usb_template.h> 66#endif /* USB_GLOBAL_INCLUDE_FILE */ 67 68#define MTP_BREQUEST 0x08 69 70enum { 71 STRING_LANG_INDEX, 72 STRING_MTP_DATA_INDEX, 73 STRING_MTP_CONFIG_INDEX, 74 STRING_MTP_VENDOR_INDEX, 75 STRING_MTP_PRODUCT_INDEX, 76 STRING_MTP_SERIAL_INDEX, 77 STRING_MTP_MAX, 78}; 79 |
80#define STRING_MTP_DATA \ 81 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ 82 'M', 0, 'T', 0, 'P', 0, \ 83 ' ', 0, 'I', 0, 'n', 0, 't', 0, \ 84 'e', 0, 'r', 0, 'f', 0, 'a', 0, \ 85 'c', 0, 'e', 0, 86 87#define STRING_MTP_CONFIG \ --- 15 unchanged lines hidden (view full) --- 103 104#define STRING_MTP_SERIAL \ 105 'J', 0, 'u', 0, 'n', 0, 'e', 0, \ 106 ' ', 0, '2', 0, '0', 0, '0', 0, \ 107 '8', 0, 108 109/* make the real string descriptors */ 110 |
111USB_MAKE_STRING_DESC(STRING_MTP_DATA, string_mtp_data); 112USB_MAKE_STRING_DESC(STRING_MTP_CONFIG, string_mtp_config); 113USB_MAKE_STRING_DESC(STRING_MTP_VENDOR, string_mtp_vendor); 114USB_MAKE_STRING_DESC(STRING_MTP_PRODUCT, string_mtp_product); 115USB_MAKE_STRING_DESC(STRING_MTP_SERIAL, string_mtp_serial); 116 117/* prototypes */ 118 --- 120 unchanged lines hidden (view full) --- 239 * Return values: 240 * NULL: Failure. No such string. 241 * Else: Success. Pointer to string descriptor is returned. 242 *------------------------------------------------------------------------*/ 243static const void * 244mtp_get_string_desc(uint16_t lang_id, uint8_t string_index) 245{ 246 static const void *ptr[STRING_MTP_MAX] = { |
247 [STRING_LANG_INDEX] = &usb_string_lang_en, |
248 [STRING_MTP_DATA_INDEX] = &string_mtp_data, 249 [STRING_MTP_CONFIG_INDEX] = &string_mtp_config, 250 [STRING_MTP_VENDOR_INDEX] = &string_mtp_vendor, 251 [STRING_MTP_PRODUCT_INDEX] = &string_mtp_product, 252 [STRING_MTP_SERIAL_INDEX] = &string_mtp_serial, 253 }; 254 255 static const uint8_t dummy_desc[0x12] = { --- 5 unchanged lines hidden (view full) --- 261 if (string_index == 0xEE) { 262 /* 263 * By returning this string LibMTP will automatically 264 * pickup our device. 265 */ 266 return (dummy_desc); 267 } 268 if (string_index == 0) { |
269 return (&usb_string_lang_en); |
270 } 271 if (lang_id != 0x0409) { 272 return (NULL); 273 } 274 if (string_index < STRING_MTP_MAX) { 275 return (ptr[string_index]); 276 } 277 return (NULL); 278} |