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_IDEController.h"
39 
40 #define	IDE_GETINSTANCE		"IDE_CONTROLLER,GET_INSTANCE"
41 #define	IDE_ENUMINSTANCES	"IDE_CONTROLLER,ENUM_INSTANCES"
42 #define	IDE_ENUMINSTANCENAMES	"IDE_CONTROLLER,ENUM_INSTANCENAMES"
43 #define	IDE_CREATEINSTANCE	"IDE_CONTROLLER,CREATE_INSTANCE"
44 #define	IDE_DELETEINSTANCE	"IDE_CONTROLLER,DELETE_INSTANCE"
45 #define	IDE_SETINSTANCE		"IDE_CONTROLLER,SET_INSTANCE"
46 #define	IDE_GETPROPERTY		"IDE_CONTROLLER,GET_PROPERTY"
47 #define	IDE_SETPROPERTY		"IDE_CONTROLLER,SET_PROPERTY"
48 #define	IDE_INVOKEMETHOD	"IDE_CONTROLLER,INVOKE_METHOD"
49 #define	IDE_EXECQUERY		"IDE_CONTROLLER,EXEC_QUERY"
50 
51 /*
52  * Solaris_IDEController 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 /*
60  * Name: cp_getInstance_Solaris_IDEController
61  *
62  * Description: Returns an instance which matches the passed in object path
63  * if found.
64  *
65  * Parameters:
66  *      pOP - An CCIMObjectPath * which contains the information on
67  *      the class for which to find the instance.
68  * Returns:
69  *      CCIMInstance * if matched instance is found. Otherwise, NULL.
70  */
71 /* ARGSUSED */
72 CCIMInstance*
cp_getInstance_Solaris_IDEController(CCIMObjectPath * pOP)73 cp_getInstance_Solaris_IDEController(CCIMObjectPath* pOP)
74 {
75 	CCIMInstance		*inst = NULL;
76 	CCIMPropertyList	*pCurPropList;
77 	dm_descriptor_t		idectrl_descriptor;
78 	char			*name;
79 	int			error;
80 
81 	if (pOP == NULL ||
82 	    pOP->mKeyProperties == NULL) {
83 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
84 		NULL, NULL, &error);
85 	    return ((CCIMInstance *)NULL);
86 	}
87 
88 	pCurPropList = pOP->mKeyProperties;
89 	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
90 	    &error);
91 
92 	if (error != 0 || name == NULL) {
93 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
94 		NULL, &error);
95 	    return ((CCIMInstance*)NULL);
96 	}
97 
98 	idectrl_descriptor =
99 	    dm_get_descriptor_by_name(DM_CONTROLLER, name, &error);
100 
101 	/*
102 	 * Not found. Return a null instance.
103 	 */
104 
105 	if (error == ENODEV) {
106 	    return ((CCIMInstance *)NULL);
107 	}
108 
109 	if (error != 0) {
110 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
111 		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
112 	    return ((CCIMInstance*)NULL);
113 	}
114 
115 	/* Turn this descriptor in to a ide controller instance */
116 
117 	inst = ctrl_descriptor_toCCIMInstance(
118 	    hostName, idectrl_descriptor, IDE_CONTROLLER, &error);
119 	dm_free_descriptor(idectrl_descriptor);
120 
121 	if (error != 0) {
122 	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
123 		IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL,
124 		&error);
125 	    return ((CCIMInstance*)NULL);
126 	}
127 
128 	return (inst);
129 }
130 
131 /*
132  * Name: cp_enumInstances_Solaris_IDEController
133  *
134  * Description: Returns an instance list of IDE controllers, if any found.
135  *
136  * Parameters:
137  *      pOP - An CCIMObjectPath * which contains the information on
138  *      the class for which to find the instances.
139  * Returns:
140  *      CCIMInstanceList * if matches are found. Otherwise, NULL.
141  */
142 
143 /* ARGSUSED */
144 CCIMInstanceList*
cp_enumInstances_Solaris_IDEController(CCIMObjectPath * pOP)145 cp_enumInstances_Solaris_IDEController(CCIMObjectPath* pOP)
146 {
147 	CCIMInstanceList	*instList = NULL;
148 	dm_descriptor_t		*idectrl_descriptorp;
149 	int			error;
150 	int			filter[1];
151 
152 	filter[0] = DM_FILTER_END;
153 
154 	idectrl_descriptorp = dm_get_descriptors(DM_CONTROLLER, filter,
155 	    &error);
156 
157 	if (idectrl_descriptorp == NULL ||
158 	    idectrl_descriptorp[0] == NULL) {
159 	    return ((CCIMInstanceList *)NULL);
160 	}
161 	if (error != 0) {
162 	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
163 		DM_GET_DESCRIPTORS, NULL, &error);
164 	    return ((CCIMInstanceList *)NULL);
165 	}
166 
167 	/* convert controller to CCIMInstanceList */
168 	instList = ctrl_descriptors_toCCIMInstanceList(IDE_CONTROLLER,
169 	    idectrl_descriptorp, &error, 2, "ata", "pcata");
170 	dm_free_descriptors(idectrl_descriptorp);
171 
172 	if (error != 0) {
173 	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
174 		IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
175 	    return ((CCIMInstanceList *)NULL);
176 	}
177 
178 	return (instList);
179 }
180 
181 /*
182  * Name: cp_enumInstanceNames_Solaris_IDEController
183  *
184  * Description: Returns an objectPath list of IDE controllers, if any found.
185  *
186  * Parameters:
187  *      pOP - An CCIMObjectPath * which contains the information on
188  *      the class for which to find the instances.
189  * Returns:
190  *      CCIMObjectPathList * if matched instances are found. Otherwise, NULL.
191  */
192 
193 /* ARGSUSED */
194 CCIMObjectPathList*
cp_enumInstanceNames_Solaris_IDEController(CCIMObjectPath * pOP)195 cp_enumInstanceNames_Solaris_IDEController(CCIMObjectPath * pOP) {
196 
197 	CCIMInstanceList	*instList;
198 	CCIMObjectPathList	*objList = NULL;
199 	int			error;
200 
201 	if (pOP == NULL) {
202 	    util_handleError(IDE_ENUMINSTANCENAMES, CIM_ERR_INVALID_PARAMETER,
203 		NULL, NULL, &error);
204 	    return ((CCIMObjectPathList *)NULL);
205 	}
206 
207 	/*
208 	 * Call in to enumInstances and then convert the instance list in
209 	 * to an object list.
210 	 */
211 
212 	instList = cp_enumInstances_Solaris_IDEController(pOP);
213 
214 	if (instList != NULL) {
215 	    objList = cim_createObjectPathList(instList);
216 	    cim_freeInstanceList(instList);
217 	}
218 
219 	return (objList);
220 }
221 
222 /*
223  * Creating an instance of a Solaris_IDEController is not supported.
224  */
225 
226 /* ARGSUSED */
227 CCIMObjectPath*
cp_createInstance_Solaris_IDEController(CCIMObjectPath * pOP,CCIMInstance * pInst)228 cp_createInstance_Solaris_IDEController(
229     CCIMObjectPath* pOP, CCIMInstance* pInst)
230 {
231 	int	error;
232 
233 	util_handleError(IDE_CREATEINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
234 	    NULL, &error);
235 	return ((CCIMObjectPath*)NULL);
236 }
237 
238 /*
239  * Deleting an instance of a Solaris_IDEController is not supported.
240  */
241 
242 /* ARGSUSED */
243 CIMBool
cp_deleteInstance_Solaris_IDEController(CCIMObjectPath * pInst)244 cp_deleteInstance_Solaris_IDEController(CCIMObjectPath* pInst)
245 {
246 	int	error;
247 
248 	util_handleError(IDE_DELETEINSTANCE,
249 	    CIM_ERR_NOT_SUPPORTED, NULL, NULL, &error);
250 	return (cim_false);
251 }
252 
253 /*
254  * Name: cp_getProperty_Solaris_IDEController
255  *
256  * Description: Returns the property requested, if found.
257  *
258  * Parameters:
259  *	pOP - An CCIMObjectPath * which contains the information on
260  *	the class for which to find the instances.
261  * Returns:
262  *	CCIMProperty * if found.
263  */
264 
265 /* ARGSUSED */
266 CCIMProperty	*
cp_getProperty_Solaris_IDEController(CCIMObjectPath * pOP,char * pPropName)267 cp_getProperty_Solaris_IDEController(CCIMObjectPath *pOP,
268     char *pPropName)
269 {
270 
271 	CCIMProperty	*prop = NULL;
272 	CCIMInstance	*inst = NULL;
273 	int		error = 0;
274 
275 	if (pOP == NULL) {
276 	    util_handleError(IDE_GETPROPERTY, CIM_ERR_INVALID_PARAMETER, NULL,
277 		NULL, &error);
278 	    return ((CCIMProperty *)NULL);
279 	}
280 
281 	inst = cp_getInstance_Solaris_IDEController(pOP);
282 	if (inst == NULL) {
283 	    return ((CCIMProperty *)NULL);
284 	}
285 
286 	prop = cim_getProperty(inst, pPropName);
287 	cim_freeInstance(inst);
288 	return (prop);
289 }
290 /*
291  * Setting an instance of a Solaris_IDEController is not supported.
292  */
293 
294 /* ARGSUSED */
295 CIMBool
cp_setInstance_Solaris_IDEController(CCIMObjectPath * pOP,CCIMInstance * pInst)296 cp_setInstance_Solaris_IDEController(CCIMObjectPath* pOP, CCIMInstance* pInst)
297 {
298 
299 	int	error;
300 
301 	util_handleError(IDE_SETINSTANCE, CIM_ERR_NOT_SUPPORTED, NULL,
302 	    NULL, &error);
303 	return (cim_false);
304 }
305 
306 /*
307  * Setting a property on an instance of a Solaris_IDEController is not
308  * supported.
309  */
310 /* ARGSUSED */
311 CIMBool
cp_setProperty_Solaris_IDEController(CCIMObjectPath * pOP,CCIMProperty * pProp)312 cp_setProperty_Solaris_IDEController(CCIMObjectPath* pOP, CCIMProperty* pProp)
313 {
314 
315 	int	error;
316 
317 	util_handleError(IDE_SETPROPERTY, CIM_ERR_NOT_SUPPORTED, NULL,
318 	    NULL, &error);
319 	return (cim_false);
320 }
321 
322 /*
323  * No methods available on an instance of a Solaris_IDEController
324  */
325 
326 /* ARGSUSED */
327 CCIMProperty*
cp_invokeMethod_Solaris_IDEController(CCIMObjectPath * op,cimchar * methodName,CCIMPropertyList * inParams,CCIMPropertyList * outParams)328 cp_invokeMethod_Solaris_IDEController(CCIMObjectPath* op, cimchar* methodName,
329     CCIMPropertyList* inParams, CCIMPropertyList* outParams)
330 {
331 	CCIMProperty	*retVal = (CCIMProperty*)NULL;
332 	return (retVal);
333 }
334 
335 /*
336  * Name: cp_execQuery_Solaris_IDEController
337  *
338  * Description:
339  * Returns an instance list which matches the query if any are found.
340  *
341  * Parameters:
342  *      CCIMObjectPath *op - An CCIMObjectPath * which contains the
343  *      information on the class for which to find the instances.
344  *
345  *      selectList - Not used
346  *      nonJoinExp - Not used
347  *
348  * Returns:
349  *      CCIMInstanceList * if matched instances are found. Otherwise, NULL.
350  */
351 /*
352  * Currently, there is no WQL parser for the C providers. As a result,
353  * what is returned to the CIMOM is a list of instances with
354  * a NULL value at the beginning of the list. This NULL value indicates
355  * to the CIMOM that it must do the filtering for the client.
356  */
357 
358 /* ARGSUSED */
359 CCIMInstanceList*
cp_execQuery_Solaris_IDEController(CCIMObjectPath * op,cimchar * selectList,cimchar * nonJoinExp,cimchar * queryExp,int queryType)360 cp_execQuery_Solaris_IDEController(CCIMObjectPath *op, cimchar *selectList,
361     cimchar *nonJoinExp, cimchar *queryExp, int queryType)
362 {
363 	CCIMInstanceList	*instList = NULL;
364 	CCIMInstanceList	*result;
365 	CCIMInstance		*emptyInst;
366 	CCIMException		*ex;
367 	int			error;
368 
369 	if (op == NULL) {
370 	    util_handleError(IDE_EXECQUERY, CIM_ERR_INVALID_PARAMETER, NULL,
371 		NULL, &error);
372 	    return ((CCIMInstanceList *)NULL);
373 	}
374 
375 	instList = cp_enumInstances_Solaris_IDEController(op);
376 
377 	if (instList == NULL) {
378 	    return ((CCIMInstanceList *)NULL);
379 	}
380 	/*
381 	 * Create a null instance and add it to the beginning
382 	 * of the list to indicate to the CIMOM that no filtering
383 	 * was done.
384 	 */
385 
386 	emptyInst = cim_createInstance("");
387 	if (emptyInst == NULL) {
388 	    ex = cim_getLastError();
389 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
390 		CREATE_INSTANCE_FAILURE, ex, &error);
391 	    cim_freeInstanceList(instList);
392 	    return ((CCIMInstanceList *)NULL);
393 	}
394 
395 	result = cim_createInstanceList();
396 	if (result == NULL) {
397 	    ex = cim_getLastError();
398 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
399 		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
400 	    cim_freeInstance(emptyInst);
401 	    cim_freeInstanceList(instList);
402 	    return ((CCIMInstanceList *)NULL);
403 	}
404 
405 	result = cim_addInstance(result, emptyInst);
406 	if (result == NULL) {
407 	    ex = cim_getLastError();
408 	    util_handleError(IDE_EXECQUERY, CIM_ERR_FAILED,
409 		ADD_INSTANCE_FAILURE, ex, &error);
410 	    cim_freeInstanceList(instList);
411 	    return ((CCIMInstanceList *)NULL);
412 	}
413 
414 	/*
415 	 * Since copying the original list to the new list will
416 	 * leave no way to free the original list, manually
417 	 * concatenate the original list to the new one.
418 	 */
419 
420 	result->mNext = instList;
421 	return (result);
422 }
423