Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue in generating a matching dictionary of multiple VID/PIDs



Hi,

I hope this is the right list for me to post this query. I am trying
to create a matching dictionary from the Info.plist for my CFPlugin
bundle for my usb smart card reader(SPR532). When the Info.plist
contains only one element of matching VID/PID, I am able to
successfully match the device from the code. But, when the Info.plist
contains an <array> of values for both the vendorID and ProductID key
item, The IOServiceGetMatchingServices function is not giving any
matching device. Is it possible to add an array of VIDs/PIDs to
generate my matching dictionary. I tried creating two arrays for the
key "kUSBVendorID" and kUSBProductID". What am I doing wrong here. Any
lead in this line would be of great help to me.

Attaching the code snippet I am using
----------------------snip--------------------------------
const void * blobValue =
CFDictionaryGetValue(dict,	CFSTR(PCSCLITE_MANUKEY_NAME));
if (!blobValue) {
syslog(LOG_CRIT, "error getting vendor ID from bundle\n");
return FALSE;
}

CFStringRef strValue;
CFMutableArrayRef vid_array =
CFArrayCreateMutable(kCFAllocatorDefault,
kCFNumberSInt32Type*reader_nb, &kCFTypeArrayCallBacks);
CFMutableArrayRef pid_array =
CFArrayCreateMutable(kCFAllocatorDefault,
kCFNumberSInt32Type*reader_nb, &kCFTypeArrayCallBacks);


if (CFGetTypeID(blobValue) == CFArrayGetTypeID())
{
	CFArrayRef vendorArray = blobValue;	
	CFArrayRef productArray;	
	CFArrayRef friendlyNameArray;

	// get list of ProductID
	productArray = CFDictionaryGetValue(dict, CFSTR(PCSCLITE_PRODKEY_NAME));
	if (!productArray) {
		syslog(LOG_CRIT, "error getting product ID from bundle");
		return FALSE;
	}

	// get list of FriendlyName
	friendlyNameArray = CFDictionaryGetValue(dict,
CFSTR(PCSCLITE_FRIENDLYNAME_KEY));
	if (!friendlyNameArray) {
		syslog(LOG_CRIT, "error getting product name from bundle");
		return FALSE;
	}

	int reader_nb = CFArrayGetCount(vendorArray);
	ReaderInfoCount = reader_nb;
	driverBundle = (ProdBundleInfo *) calloc ( ReaderInfoCount,
sizeof(ProdBundleInfo) );

	if (reader_nb != CFArrayGetCount(productArray)) {
		syslog(LOG_CRIT,
			"Malformed Info.plist: %d vendors and %d products",
			reader_nb, CFArrayGetCount(productArray));
		return FALSE;
	}

	if (reader_nb != CFArrayGetCount(friendlyNameArray)) {
		syslog(LOG_CRIT,
			"Malformed Info.plist: %d vendors and %d friendlynames",
			reader_nb, CFArrayGetCount(friendlyNameArray));
		return FALSE;
	}

	for (j=0; j<reader_nb; j++) {
	strValue = CFArrayGetValueAtIndex(vendorArray, j);
	(driverBundle+j)->m_vendorId =
strtoul(CFStringGetCStringPtr(strValue, CFStringGetSystemEncoding()),
NULL, 16);
	// vid = (driverBundle+j)->m_vendorId;

	strValue = CFArrayGetValueAtIndex(productArray, j);
	(driverBundle+j)->m_productId =
strtoul(CFStringGetCStringPtr(strValue,	CFStringGetSystemEncoding()),
NULL, 16);
	// pid = (driverBundle+j)->m_vendorId;		

	CFArrayAppendValue(vid_array,  (driverBundle+j)->m_vendorId);
CFArrayAppendValue(pid_array, (driverBundle+j)->m_productId);

		// if (!(driverBundle+j)->m_libPath) driverBundle->m_libPath =
strdup(libPath);
#ifdef SYSLOG_DBG
		syslog(LOG_CRIT, "[%d] - VendorID: 0x%04X ProductID: 0x%04X Friendly
name: %s",
			j+1, (driverBundle+j)->m_vendorId, (driverBundle+j)->m_productId,
(driverBundle+j)->m_friendlyName);
		// syslog(LOG_CRIT, "Driver: %s", driverBundle->m_libPath);
#endif
//		}

	 CFDictionaryAddValue(USBMatch, CFSTR(kUSBVendorID), vid_array);
	 CFDictionaryAddValue(USBMatch, CFSTR(kUSBProductID), pid_array);

// CFRelease(vid_array);
	// CFRelease(pid_array);

}
else
{
	ReaderInfoCount = 1;
	driverBundle = (ProdBundleInfo *) calloc ( ReaderInfoCount,
sizeof(ProdBundleInfo) );
	syslog(LOG_CRIT, "Single VID PID entry found");

	strValue = blobValue;

	driverBundle->m_vendorId = strtoul(CFStringGetCStringPtr(strValue,
			CFStringGetSystemEncoding()), NULL, 16);

	strValue = (CFStringRef) CFDictionaryGetValue(dict,	CFSTR(kUSBProductID));
	if (!strValue)
	{
		syslog(LOG_CRIT, "error getting product ID from bundle");
		return FALSE;
	}
	driverBundle->m_productId = strtoul(CFStringGetCStringPtr(strValue,
		CFStringGetSystemEncoding()), NULL, 16);

	CFDictAddProd ( USBMatch, driverBundle->m_vendorId, driverBundle->m_productId);

	strValue = (CFStringRef) CFDictionaryGetValue(dict,
CFSTR(PCSCLITE_FRIENDLYNAME_KEY));
	if (!strValue)
	{
		syslog(LOG_CRIT, "error getting product friendly name from bundle");
		driverBundle->m_friendlyName = strdup("unnamed device");
	}
	else
	{		
		const char *cstr = CFStringGetCStringPtr(strValue,
CFStringGetSystemEncoding());
		driverBundle->m_friendlyName = strdup(cstr);
	}

	syslog(LOG_CRIT, "VendorID: 0x%04X ProductID: 0x%04X Friendly name: %s",
		driverBundle->m_vendorId, driverBundle->m_productId,
driverBundle->m_friendlyName);
}
----------------------snip--------------------------------

Thanks
Joseph
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.