1/*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*
25 *  PCSCDriverBundle.h
26 *  SmartCardServices
27 */
28
29#ifndef _H_XPCSCDRIVERBUNDLE
30#define _H_XPCSCDRIVERBUNDLE
31
32#include <string>
33#include <vector>
34#include <MacTypes.h>
35#include <security_utilities/refcount.h>
36#include <security_utilities/osxcode.h>
37#include "PCSCDevice.h"
38
39#if defined(__cplusplus)
40
41namespace PCSCD {
42
43class DeviceDescription
44{
45public:
46
47	DeviceDescription() { }
48	DeviceDescription(uint16_t vendor, uint16_t product, std::string name) :
49		mVendor(vendor), mProduct(product),
50		mDeviceClass(0), mDeviceSubClass(0), mDeviceProtocol(0),
51		mFriendlyName(name) {}
52	DeviceDescription(uint8_t deviceClass, uint8_t deviceSubClass, uint8_t protocol, std::string name) :
53		mVendor(0), mProduct(0),
54		mDeviceClass(deviceClass), mDeviceSubClass(deviceSubClass), mDeviceProtocol(protocol),
55		mFriendlyName(name) {}
56
57	bool operator < (const DeviceDescription &other) const throw();
58
59	uint8_t interfaceClass() const	{ return mDeviceClass; }
60	uint16_t vendorid() const { return mVendor; }
61	uint16_t productid() const { return mProduct; }
62	std::string name() const { return mFriendlyName; }
63
64	void dump();
65
66protected:
67	// Match types from <IOKit/USB.h> for IOUSBDeviceDescriptor
68
69	uint16_t mVendor;			// Unique vendor's manufacturer code assigned by the USB-IF
70	uint16_t mProduct;			// Manufacturer's unique product code
71
72	uint8_t mDeviceClass;
73	uint8_t mDeviceSubClass;
74	uint8_t mDeviceProtocol;
75
76	std::string mFriendlyName;	// Manufacturer's name for device
77};
78
79/*
80 * An aggregation of useful information on a driver bundle in the
81 * drop directory.
82 */
83
84class DriverBundle : public LoadableBundle
85{
86private:
87	DriverBundle(const char *pathname) : LoadableBundle(pathname) { }
88
89public:
90	DriverBundle(CFBundleRef bundle);
91
92	virtual ~DriverBundle() throw();
93
94	bool operator < (const DriverBundle &other) const throw();
95
96	void addProduct(DeviceDescription *dev) { mDeviceDescriptions.push_back(dev); }
97
98	uint32_t matches(const Device &device, std::string &name) const;
99
100	enum
101	{
102		eMatchNone = 0,
103		eMatchInterfaceClass,	// must be less than eMatchVendorSpecific
104		eMatchVendorSpecific
105	};
106
107protected:
108	void initialize(CFDictionaryRef dict);
109
110private:
111
112	typedef std::vector<DeviceDescription *> DeviceDescriptions;
113    typedef DeviceDescriptions::iterator DeviceDescriptionIterator;
114    typedef DeviceDescriptions::const_iterator ConstDeviceDescriptionIterator;
115	DeviceDescriptions mDeviceDescriptions;
116
117	std::string getStringAttr(CFDictionaryRef dict, CFStringRef key);
118	std::string getStringAttr(CFArrayRef arr, CFIndex idx);
119	void dump();
120};
121
122} // end namespace PCSCD
123
124#endif /* __cplusplus__ */
125
126#endif /* _H_XPCSCDRIVERBUNDLE */
127