📄 usbconf.c
字号:
get_nvflash_page();
OMgetInt(omMetaDataPage2Id, OMCURRENT, &page_id);
/*
** This is a pretty simple-minded test for NVRAM validity.
** Is it designed to be very fast, but doesn't offer any protection
** against NVRAM corruption. This is probably OK, since this USB
** config info will most likely only ever be used in the factory.
*/
nvram_invalid = (page_id != 2);
}
#endif
/* string description table */
ASSERT(sizeof(USB_str_0) == USB_str_0[0]);
USB_Conf.StrDescTable[0] = USB_str_0;
USBGetDeviceID(DeviceID, sizeof(DeviceID));
USB_Conf.DeviceID = DeviceID;
key = (Uint8 *)"MFG:";
if (ParseDeviceID(USB_Conf.DeviceID, key, USB_str_1))
USB_Conf.StrDescTable[1] = USB_str_1;
else
USB_Conf.StrDescTable[1] = USB_str_unknown;
key = (Uint8 *)"DES:";
if (ParseDeviceID(USB_Conf.DeviceID, key, USB_str_2))
USB_Conf.StrDescTable[2] = USB_str_2;
else
USB_Conf.StrDescTable[2] = USB_str_unknown;
/*
* Construct serial no. string descriptor USB_str_3[] from the
* "offical" Serial Number.
*/
n = USBGetSerialNo(serial_no, sizeof(serial_no));
USB_str_3[0] = 2*n + 2; /* descriptor length */
USB_str_3[1] = 3; /* descriptor type */
/* convert ASCII to unicode */
for (i = 0; i < 2*n; i += 2) {
c = serial_no[i/2];
if (c < ' ' || c > 'z')
c = '?';
USB_str_3[i+2] = c;
USB_str_3[i+3] = 0;
}
USB_Conf.StrDescTable[3] = USB_str_3;
ASSERT(sizeof(USB_str_4) == USB_str_4[0]);
USB_Conf.StrDescTable[4] = USB_str_4;
ASSERT(sizeof(USB_str_5) == USB_str_5[0]);
USB_Conf.StrDescTable[5] = USB_str_5;
ASSERT(sizeof(USB_str_6) == USB_str_6[0]);
USB_Conf.StrDescTable[6] = USB_str_6;
ASSERT(sizeof(USB_str_7) == USB_str_7[0]);
USB_Conf.StrDescTable[7] = USB_str_7;
ASSERT(sizeof(USB_str_n) == USB_str_n[0]);
USB_Conf.StrDescTable[8] = USB_str_n;
ASSERT(sizeof(USB_str_lerr) == USB_str_lerr[0]);
USB_Conf.StrDescTable[9] = USB_str_lerr;
/* Configuration - Full Speed and High Speed */
ASSERT(sizeof(FSConfDesc) == sizeof(HSConfDesc));
ASSERT(sizeof(FSConfDesc) <= CONFIG_SIZE_MAX);
USB_Conf.ConfigurationSize = sizeof(FSConfDesc);
for (i = 0; i < USB_Conf.ConfigurationSize; i++) {
USB_Conf.FSConfDesc[i] = FSConfDesc[i];
USB_Conf.HSConfDesc[i] = HSConfDesc[i];
}
USB_Conf.FSConfDesc[2] =
USB_Conf.HSConfDesc[2] = LOB(USB_Conf.ConfigurationSize);
USB_Conf.FSConfDesc[3] =
USB_Conf.HSConfDesc[3] = HIB(USB_Conf.ConfigurationSize);
/* Device Descriptor */
ASSERT(sizeof(DevDesc) == DevDesc[0]);
USBGetVidPid(&Vid, &Pid);
DevDesc[ 8] = LOB(Vid); /* Vendor ID */
DevDesc[ 9] = HIB(Vid); /* Vendor ID */
DevDesc[10] = LOB(Pid); /* Product ID */
DevDesc[11] = HIB(Pid); /* Product ID */
USB_Conf.DevDesc = DevDesc;
/* Device Qualifier */
ASSERT(sizeof(DevQualifierDesc) == DevQualifierDesc[0]);
USB_Conf.DevQualifierDesc = DevQualifierDesc;
/* String Descriptor Information */
USB_Conf.StrDescCount = STR_DESC_CNT;
USB_Conf.StrErrorIndex = STR_INDEX_ERR; /* 8 'Illegal Index' */
USB_Conf.StrErrorLanguage = STR_LANGUAGE_ERR; /* 9 'Language Error' */
USB_Conf.HIDDescriptor = HIDDescriptor;
USB_Conf.HIDDescriptor_size = HIDDescriptor[0];
USB_Conf.HIDClassReportDesc = HIDClassReportDesc;
USB_Conf.HIDClassReportDesc_size = sizeof(HIDClassReportDesc);
USB_Conf.HIDinterface = HID_IFACE;
}
/*****************************************************************************/
/*
* Set up string descriptor based on Device ID entry. Look for key string
* ("MFG:" or "DES:"), return unicode descriptor string. Returns FALSE if
* Device ID string is invalid.
*/
static Boolean ParseDeviceID(Uint8 *DeviceID, Uint8 *key, Uint8 *descriptor)
{
int i;
Uint8 *p, *k, *descriptor_length;
p = DeviceID+2;
for (i = 0; i < DeviceID[1] - 6; i++) {
p = &DeviceID[2+i];
k = key;
while (*p++ == *k++) {
if (*k == 0) {
/* Set initial string length to 2, type to 3 */
descriptor_length = descriptor;
*descriptor++ = 2;
*descriptor++ = 3;
/*
* Found key. Copy characters up to terminal ";",
* converting to unicode.
*/
while (*p != ';') {
if (*descriptor_length >= 128)
return FALSE;
*descriptor++ = *p++;
*descriptor++ = 0;
*descriptor_length += 2;
}
/* ignore trailing space */
if (*(descriptor-1) == ' ')
*descriptor_length -= 2;
/* no characters, no good */
if (*descriptor_length <= 2)
return FALSE;
return TRUE;
}
}
}
return FALSE;
}
/*****************************************************************************/
int USBGetSerialNo(Uint8 *s, int max_len)
{
#ifdef SERIAL_NO_STRING
/* return string of dummy serial number */
strcpy(s, SERIAL_NO_STRING);
#else
int should_report_serial_number = FALSE;
#ifdef BOOTCODE
if (!nvram_invalid)
#endif
{
OMgetInt(omUSBSerialNumberActive,
OMCURRENT,
&should_report_serial_number);
}
if (should_report_serial_number)
{
OMgetString(omSerialNumber, OMCURRENT, (char *)s, max_len);
}
else
{
/* On the manufacturing line, all devices should report serial number
** zero to keep from installing hundreds of copies of the driver.
*/
strcpy((char *)s, "000000000000000");
}
#endif
return strlen((char *)s);
}
void USBGetVidPid(Uint16 *Vid, Uint16 *Pid)
{
#ifdef BOOTCODE
if (nvram_invalid)
{
*Vid = VENDOR_ID; /* Vendor ID Lexmark */
*Pid = PRODUCT_ID;
}
else
#endif
{
int vid_prop, pid_prop;
OMgetInt(omUSBVendorID, OMCURRENT, &vid_prop);
OMgetInt(omUSBProductID, OMCURRENT, &pid_prop);
*Vid = (Uint16)vid_prop;
*Pid = (Uint16)pid_prop;
}
}
#ifdef BOOTCODE
/* default string used if Device ID bad or unavailable from NVRAM */
static Uint8 DeviceID_default[] = {
#ifdef LEX5100
0, 87,
/* MFG:Lexmark ; */
/* CMD:CPDNPA001; */
/* MODEL:X5100 Series; */
/* CLASS:Printer; */
/* DES:Lexmark X5100 Series; */
'M','F','G',':','L','e','x','m','a','r','k',' ',';',
'C','M','D',':','C','P','D','N','P','A','0','0','1',';',
'M','O','D','E','L',':','X','5','1','0','0',' ','S','e','r','i','e','s',';',
'C','L','A','S','S',':','P','r','i','n','t','e','r',';',
'D','E','S',':','L','e','x','m','a','r','k',' ','X','5','1','0','0',' ',
'S','e','r','i','e','s',';'
#endif
#ifdef SEA /* SEA** */
0, 85,
/* MFG:Lexmark ; */
/* CMD:CPDNPA003; */
/* MODEL:6200 Series; */
/* CLASS:Printer; */
/* DES:Lexmark 6200 Series; */
'M','F','G',':','L','e','x','m','a','r','k',' ',';',
'C','M','D',':','C','P','D','N','P','A','0','0','3',';',
'M','O','D','E','L',':','6','2','0','0',' ','S','e','r','i','e','s',';',
'C','L','A','S','S',':','P','r','i','n','t','e','r',';',
'D','E','S',':','L','e','x','m','a','r','k',' ','6','2','0','0',' ',
'S','e','r','i','e','s',';'
#endif
#ifdef UNBRIDLED
0, 85,
/* MFG:Lexmark ; */
/* CMD:CPDNPA003; */
/* MODEL:5200 Series; */
/* CLASS:Printer; */
/* DES:Lexmark 5200 Series; */
'M','F','G',':','L','e','x','m','a','r','k',' ',';',
'C','M','D',':','C','P','D','N','P','A','0','0','3',';',
'M','O','D','E','L',':','5','2','0','0',' ','S','e','r','i','e','s',';',
'C','L','A','S','S',':','P','r','i','n','t','e','r',';',
'D','E','S',':','L','e','x','m','a','r','k',' ','5','2','0','0',' ',
'S','e','r','i','e','s',';'
#endif
#ifdef CHARISMATIC /* CHA** */
0, 85,
/* MFG:Lexmark ; */
/* CMD:CPDNPA003; */
/* MODEL:P910 Series; */
/* CLASS:Printer; */
/* DES:Lexmark P910 Series; */
'M','F','G',':','L','e','x','m','a','r','k',' ',';',
'C','M','D',':','C','P','D','N','P','A','0','0','3',';',
'M','O','D','E','L',':','P','9','1','0',' ','S','e','r','i','e','s',';',
'C','L','A','S','S',':','P','r','i','n','t','e','r',';',
'D','E','S',':','L','e','x','m','a','r','k',' ','P','9','1','0',' ',
'S','e','r','i','e','s',';'
#endif
#ifdef TIMEX /* CHA** */
0, 0x53,
/* MFG:Dell ; */
/* CMD:CPDNPA003; */
/* MODEL:Photo AIO 942 */
/* CLASS:Printer; */
/* DES:Dell Photo AIO 942; */
'M','F','G',':','D','e','l','l',' ',';',
'C','M','D',':','C','P','D','N','P','A','0','0','3',';',
'M','O','D','E','L',':','P','h','o','t','o',' ','A','I','O',' ','9','4','2',';',
'C','L','A','S','S',':','P','r','i','n','t','e','r',';',
'D','E','S',':','D','e','l','l',' ','P','h','o','t','o',' ','A','I','O',' ','9','4','2',';',
#endif
};
#endif
#define MFG_STR "MFG:"
/*
** Should be:
**
** #define CMD_STR "CMD:"
**
** and we should be getting the command string from somewhere, but where?
*/
#define CMD_STR ";CMD:"
#define MODEL_STR ";MODEL:"
#define CLASS_STR ";CLASS:Printer"
#define DES_STR ";DES:"
#define LENGTH_SIZE 2
void USBGetDeviceID(Uint8 *DeviceID, int max_len)
{
#ifdef BOOTCODE
if (nvram_invalid)
{
int i;
ASSERT(sizeof(DeviceID_default) == DeviceID_default[1]);
for (i = 0; i < DeviceID_default[1]; i++)
DeviceID[i] = DeviceID_default[i];
}
else
#endif
{
int i=LENGTH_SIZE;
strcpy((char *)DeviceID+i, MFG_STR);
i += sizeof(MFG_STR) - 1;
OMgetString(omManufacturerName, OMCURRENT, (char *)DeviceID+i, max_len-i);
while (DeviceID[i] != '\0') i++;
strncpy((char *)DeviceID+i, CMD_STR, max_len-i);
i += sizeof(CMD_STR) - 1;
OMgetString(omUSBCommandString, OMCURRENT, (char *)DeviceID+i, max_len-i);
while (DeviceID[i] != '\0') i++;
strncpy((char *)DeviceID+i, MODEL_STR, max_len-i);
i += sizeof(MODEL_STR) - 1;
OMgetString(omPrinterModel, OMCURRENT, (char *)DeviceID+i, max_len-i);
while (DeviceID[i] != '\0') i++;
strncpy((char *)DeviceID+i, CLASS_STR, max_len-i);
i += sizeof(CLASS_STR) - 1;
strncpy((char *)DeviceID+i, DES_STR, max_len-i);
i += sizeof(DES_STR) - 1;
OMgetString(omManufacturerName, OMCURRENT, (char *)DeviceID+i, max_len-i);
while (DeviceID[i] != '\0') i++;
/*
* Make certain that there is a space between MFG and MOD
* strings when concatinating for DES string.
*/
if (DeviceID[i-1] != ' ') {
DeviceID[i-1] = ' ';
i++;
}
OMgetString(omPrinterModel, OMCURRENT, (char *)DeviceID+i, max_len-i);
while (DeviceID[i] != '\0') i++;
DeviceID[i] = ';';
DeviceID[i+1] = '\0';
/* Insert the length bytes */
DeviceID[0] = 0;
DeviceID[1] = i + 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -