1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <unistd.h>
30 #include <netdb.h>
31 #include <errno.h>
32 
33 #include "util.h"
34 #include "cimKeys.h"
35 #include "ctrl_descriptors.h"
36 #include "providerNames.h"
37 #include "messageStrings.h"
38 #include "Solaris_USBSCSIController.h"
39 
40 #define	USB_GETINSTANCE		"USBSCSI_CONTROLLER,GET_INSTANCE"
41 #define	USB_ENUMINSTANCES	"USBSCSI_CONTROLLER,ENUM_INSTANCES"
42 #define	USB_ENUMINSTANCENAMES	"USBSCSI_CONTROLLER,ENUM_INSTANCENAMES"
43 #define	USB_CREATEINSTANCE	"USBSCSI_CONTROLLER,CREATE_INSTANCE"
44 #define	USB_DELETEINSTANCE	"USBSCSI_CONTROLLER,DELETE_INSTANCE"
45 #define	USB_SETINSTANCE		"USBSCSI_CONTROLLER,SET_INSTANCE"
46 #define	USB_GETPROPERTY		"USBSCSI_CONTROLLER,GET_PROPERTY"
47 #define	USB_SETPROPERTY		"USBSCSI_CONTROLLER,SET_PROPERTY"
48 #define	USB_INVOKEMETHOD	"USBSCSI_CONTROLLER,INVOKE_METHOD"
49 #define	USB_EXECQUERY		"USBSCSI_CONTROLLER,EXEC_QUERY"
50 
51 /*
52  * Solaris_USBSCSIController provider
53  *
54  * It is important to note that all memory allocated by these functions
55  * and passed to the CIMOM, is freed by the CIMOM as the caller.
56  */
57 
58 /*
59  * Name: cp_getInstance_Solaris_USBSCSIController
60  *
61  * Description: Returns an instance which matches the passed in object path
62  * if found.
63  *
64  * Parameters:
65  *      pOP - An CCIMObjectPath * which contains the information on
66  *      the class for which to find the instance.
67  * Returns:
68  *      CCIMInstance * if matched instance is found. Otherwise, NULL.
69  */
70 
71 /* ARGSUSED */
72 CCIMInstance*
cp_getInstance_Solaris_USBSCSIController(CCIMObjectPath * pOP)73 cp_getInstance_Solaris_USBSCSIController(CCIMObjectPath* pOP)
74 {
75 	CCIMInstance		*inst = NULL;
76 	CCIMPropertyList	*pCurPropList;
77 	dm_descriptor_t		usbctrl_descriptor;
78 	char			*name;
79 	int			error;
80 
81 	if (pOP == NULL || pOP->mKeyProperties == NULL) {
82 	    util_handleError(USB_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
83 		NULL, &error);
84 	    return ((CCIMInstance *)NULL);
85 	}
86 
87 	pCurPropList = pOP->mKeyProperties;
88 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
89 	    &error);
90 
91 	if (error != 0 || name == NULL) {
92 	    util_handleError(USB_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
93 		NULL, &error);
94 	    return ((CCIMInstance*)NULL);
95 	}
96 
97 	usbctrl_descriptor =
98 	    dm_get_descriptor_by_name(DM_CONTROLLER, name, &error);
99 	/*
100 	 * Not found. Return a null instance.
101 	 */
102 
103 	if (error == ENODEV) {
104 	    return ((CCIMInstance *)NULL);
105 	}
106 
107 	if (error != 0) {
108 	    util_handleError(USB_GETINSTANCE, CIM_ERR_FAILED,
109 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
110 	    return ((CCIMInstance*)NULL);
111 	}
112 
113 	/* Turn this descriptor in to a usb controller instance */
114 
115 	inst = ctrl_descriptor_toCCIMInstance(
116 	    hostName, usbctrl_descriptor, USBSCSI_CONTROLLER, &error);
117 	dm_free_descriptor(usbctrl_descriptor);
118 
119 	if (error != 0) {
120 	    util_handleError(USB_GETINSTANCE, CIM_ERR_FAILED,
121 		USBCTRL_DESC_TO_INSTANCE_FAILURE, NULL,
122 		&error);
123 	    return ((CCIMInstance*)NULL);
124 	}
125 
126 	return (inst);
127 }
128 
129 /*
130  * Name: cp_enumInstances_Solaris_USBSCSIController
131  *
132  * Description: Returns an instance which matches the passed in object path
133  * if found.
134  *
135  * Parameters:
136  *      pOP - An CCIMObjectPath * which contains the information on
137  *      the class for which to find the instance.
138  * Returns:
139  *      CCIMInstanceList * if matched instances are found. Otherwise, NULL.
140  */
141 
142 /* ARGSUSED */
143 CCIMInstanceList*
cp_enumInstances_Solaris_USBSCSIController(CCIMObjectPath * pOP)144 cp_enumInstances_Solaris_USBSCSIController(CCIMObjectPath* pOP)
145 {
146 	CCIMInstanceList	*instList = NULL;
147 	dm_descriptor_t		*usbctrl_descriptorp;
148 	int			error;
149 	int			filter[1];
150 
151 	filter[0] = DM_FILTER_END;
152 
153 	usbctrl_descriptorp = dm_get_descriptors(DM_CONTROLLER, filter,
154 	    &error);
155 
156 	/*
157 	 * If no devices, return empty list.
158 	 */
159 	if (usbctrl_descriptorp == NULL ||
160 	    usbctrl_descriptorp[0] == NULL) {
161 	    return ((CCIMInstanceList *)NULL);
162 	}
163 	if (error != 0) {
164 	    util_handleError(USB_ENUMINSTANCES, CIM_ERR_FAILED,
165 		DM_GET_DESCRIPTORS, NULL, &error);
166 	    return ((CCIMInstanceList *)NULL);
167 	}
168 
169 	/* convert controller to CCIMInstanceList */
170 	instList = ctrl_descriptors_toCCIMInstanceList(USBSCSI_CONTROLLER,
171 	    usbctrl_descriptorp, &error, 1, "usb");
172 	dm_free_descriptors(usbctrl_descriptorp);
173 
174 	if (error != 0) {
175 	    util_handleError(USB_ENUMINSTANCES, CIM_ERR_FAILED,
176 		USBCTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
177 	    return ((CCIMInstanceList *)NULL);
178 	}
179 
180 	return (instList);
181 }
182 
183 /*
184  * Name: cp_enumInstanceNames_Solaris_USBSCSIController
185  *
186  * Description: Returns an object path list of Solaris_USBSCSIController if
187  * found.
188  *
189  * Parameters:
190  *      pOP - An CCIMObjectPath * which contains the information on
191  *      the class for which to find the instance.
192  * Returns:
193  *      CCIMObjectPathList * if matched instances are found. Otherwise, NULL.
194  */
195 
196 /* ARGSUSED */
197 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_USBSCSIController(CCIMObjectPath * pOP)198 cp_enumInstanceNames_Solaris_USBSCSIController(CCIMObjectPath * pOP) {
199 
200 	CCIMInstanceList	*instList = NULL;
201 	CCIMObjectPathList	*objList = NULL;
202 	int			error;
203 
204 	if (pOP == NULL) {
205 	    util_handleError(USB_ENUMINSTANCENAMES, CIM_ERR_INVALID_PARAMETER,
206 		NULL, NULL, &error);
207 	    return ((CCIMObjectPathList *)NULL);
208 	}
209 	/*
210 	 * Call in to enumInstances and then convert the instance list in
211 	 * to an object list.
212 	 */
213 
214 	instList = cp_enumInstances_Solaris_USBSCSIController(pOP);
215 	if (instList != NULL) {
216 	    objList = cim_createObjectPathList(instList);
217 	    cim_freeInstanceList(instList);
218 	}
219 
220 	return (objList);
221 }
222 
223 /*
224  * Creating an instance of a Solaris_USBSCSIController is not supported.
225  */
226 
227 /* ARGSUSED */
228 CCIMObjectPath*
cp_createInstance_Solaris_USBSCSIController(CCIMObjectPath * pOP,CCIMInstance * pInst)229 cp_createInstance_Solaris_USBSCSIController(
230     CCIMObjectPath* pOP, CCIMInstance* pInst)
231 {
232 	int	error;
233 
234 	util_handleError(USB_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
235 	    NULL, &error);
236 	return ((CCIMObjectPath*)NULL);
237 }
238 
239 /*
240  * Deleting an instance of a Solaris_USBSCSIController is not supported.
241  */
242 
243 /* ARGSUSED */
244 CIMBool
cp_deleteInstance_Solaris_USBSCSIController(CCIMObjectPath * pInst)245 cp_deleteInstance_Solaris_USBSCSIController(CCIMObjectPath* pInst)
246 {
247 
248 	int	error;
249 
250 	util_handleError(USB_DELETEINSTANCE, CIM_ERR_NOT_SUPPORTED,
251 	    NULL, NULL, &error);
252 	return (cim_false);
253 }
254 
255 /*
256  * Name: cp_getProperty_Solaris_USBSCSIController
257  *
258  * Description: Returns the property requested, if found.
259  *
260  * Parameters:
261  *	pOP - An CCIMObjectPath * which contains the information on
262  *	the class for which to find the instances.
263  * Returns:
264  *	CCIMProperty * if found.
265  */
266 
267 /* ARGSUSED */
268 CCIMProperty	*
cp_getProperty_Solaris_USBSCSIController(CCIMObjectPath * pOP,char * pPropName)269 cp_getProperty_Solaris_USBSCSIController(CCIMObjectPath *pOP,
270     char *pPropName)
271 {
272 
273 	CCIMProperty	*prop = NULL;
274 	CCIMInstance	*inst = NULL;
275 	int		error = 0;
276 
277 	if (pOP == NULL) {
278 	    util_handleError(USB_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
279 		NULL, &error);
280 	    return ((CCIMProperty *)NULL);
281 	}
282 
283 	inst = cp_getInstance_Solaris_USBSCSIController(pOP);
284 	if (inst == NULL) {
285 	    return ((CCIMProperty *)NULL);
286 	}
287 
288 	prop = cim_getProperty(inst, pPropName);
289 	cim_freeInstance(inst);
290 	return (prop);
291 }
292 /*
293  * Setting an instance of a Solaris_USBSCSIController is not supported.
294  */
295 
296 /* ARGSUSED */
297 CIMBool
cp_setInstance_Solaris_USBSCSIController(CCIMObjectPath * pOP,CCIMInstance * pInst)298 cp_setInstance_Solaris_USBSCSIController(CCIMObjectPath* pOP,
299 	CCIMInstance* pInst)
300 {
301 
302 	int	error;
303 
304 	util_handleError(USB_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
305 	    NULL, &error);
306 	return (cim_false);
307 }
308 
309 /*
310  * Setting properties on an instance of a Solaris_USBSCSIController is not
311  * supported.
312  */
313 
314 /* ARGSUSED */
315 CIMBool
cp_setProperty_Solaris_USBSCSIController(CCIMObjectPath * pOP,CCIMProperty * pProp)316 cp_setProperty_Solaris_USBSCSIController(CCIMObjectPath* pOP,
317 	CCIMProperty* pProp)
318 {
319 
320 	int	error;
321 
322 	util_handleError(USB_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
323 	    NULL, &error);
324 	return (cim_false);
325 }
326 
327 /*
328  * No methods avialable on an instance of a Solaris_USBSCSIController
329  */
330 
331 /* ARGSUSED */
332 CCIMProperty*
cp_invokeMethod_Solaris_USBSCSIController(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)333 cp_invokeMethod_Solaris_USBSCSIController(CCIMObjectPath* op,
334 	cimchar* methodName, CCIMPropertyList* inParams,
335 	CCIMPropertyList* outParams)
336 {
337 	CCIMProperty	*retVal = (CCIMProperty*)NULL;
338 	return (retVal);
339 }
340 
341 /*
342  * Name: cp_execQuery_Solaris_USBSCSIController
343  *
344  * Description:
345  * Returns an instance list which matches the query if any are found.
346  *
347  * Parameters:
348  *      CCIMObjectPath *op - An CCIMObjectPath * which contains the
349  *      information on the class for which to find the instances.
350  *
351  *      selectList - Not used
352  *      nonJoinExp - Not used
353  *
354  * Returns:
355  *      CCIMInstanceList * if matched instances are found. Otherwise, NULL.
356  */
357 
358 /*
359  * Currently, there is no WQL parser for the C providers. As a result,
360  * what is returned to the CIMOM is a list of instances with
361  * a NULL value at the beginning of the list. This NULL value indicates
362  * to the CIMOM that it must do the filtering for the client.
363  */
364 
365 /* ARGSUSED */
366 CCIMInstanceList*
cp_execQuery_Solaris_USBSCSIController(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)367 cp_execQuery_Solaris_USBSCSIController(CCIMObjectPath *op, cimchar *selectList,
368     cimchar *nonJoinExp, cimchar *queryExp, int queryType)
369 {
370 	CCIMInstanceList	*instList = NULL;
371 	CCIMInstanceList	*result;
372 	CCIMInstance		*emptyInst;
373 	CCIMException		*ex;
374 	int			error;
375 
376 	if (op == NULL) {
377 	    util_handleError(USB_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
378 		NULL, &error);
379 	    return ((CCIMInstanceList *)NULL);
380 	}
381 
382 	instList = cp_enumInstances_Solaris_USBSCSIController(op);
383 
384 	if (instList == NULL) {
385 	    return ((CCIMInstanceList *)NULL);
386 	}
387 	/*
388 	 * Create a null instance and add it to the beginning
389 	 * of the list to indicate to the CIMOM that no filtering
390 	 * was done.
391 	 */
392 
393 	emptyInst = cim_createInstance("");
394 	if (emptyInst == NULL) {
395 	    ex = cim_getLastError();
396 	    util_handleError(USB_EXECQUERY, CIM_ERR_FAILED,
397 		CREATE_INSTANCE_FAILURE, ex, &error);
398 	    cim_freeInstanceList(instList);
399 	    return ((CCIMInstanceList *)NULL);
400 	}
401 
402 	result = cim_createInstanceList();
403 	if (result == NULL) {
404 	    ex = cim_getLastError();
405 	    util_handleError(USB_EXECQUERY, CIM_ERR_FAILED,
406 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
407 	    cim_freeInstance(emptyInst);
408 	    cim_freeInstanceList(instList);
409 	    return ((CCIMInstanceList *)NULL);
410 	}
411 
412 	result = cim_addInstance(result, emptyInst);
413 	if (result == NULL) {
414 	    ex = cim_getLastError();
415 	    util_handleError(USB_EXECQUERY, CIM_ERR_FAILED,
416 		ADD_INSTANCE_FAILURE, ex, &error);
417 	    cim_freeInstance(emptyInst);
418 	    cim_freeInstanceList(instList);
419 	    return ((CCIMInstanceList *)NULL);
420 	}
421 
422 	/*
423 	 * Since copying the original list to the new list will
424 	 * leave no way to free the original list, manually
425 	 * concatenate the original list to the new one.
426 	 */
427 
428 	result->mNext = instList;
429 	return (result);
430 }
431