xref: /onnv-gate/usr/src/lib/libsun_ima/common/ima.c (revision 11275:616d1b95d598)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
228656SPeter.Dunlap@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237836SJohn.Forte@Sun.COM  * Use is subject to license terms.
247836SJohn.Forte@Sun.COM  */
257836SJohn.Forte@Sun.COM 
267836SJohn.Forte@Sun.COM #include <arpa/inet.h>
277836SJohn.Forte@Sun.COM #include <sys/socket.h>
287836SJohn.Forte@Sun.COM #include <sys/types.h>
297836SJohn.Forte@Sun.COM #include <stdarg.h>
307836SJohn.Forte@Sun.COM #include <stdlib.h>
317836SJohn.Forte@Sun.COM #include <string.h>
327836SJohn.Forte@Sun.COM #include <strings.h>
337836SJohn.Forte@Sun.COM #include <unistd.h>
347836SJohn.Forte@Sun.COM #include <syslog.h>
357836SJohn.Forte@Sun.COM #include <errno.h>
367836SJohn.Forte@Sun.COM #include <wchar.h>
377836SJohn.Forte@Sun.COM #include <widec.h>
387836SJohn.Forte@Sun.COM #include <libsysevent.h>
397836SJohn.Forte@Sun.COM #include <sys/nvpair.h>
407836SJohn.Forte@Sun.COM #include <fcntl.h>
417836SJohn.Forte@Sun.COM #include <stdio.h>
427836SJohn.Forte@Sun.COM #include <time.h>
437836SJohn.Forte@Sun.COM #include <libdevinfo.h>
4411271SMilos.Muzik@Sun.COM #include <sys/scsi/generic/commands.h>
4511271SMilos.Muzik@Sun.COM #include <sys/scsi/generic/status.h>
467836SJohn.Forte@Sun.COM #include <sys/scsi/adapters/iscsi_if.h>
478656SPeter.Dunlap@Sun.COM #include <sys/iscsi_protocol.h>
487836SJohn.Forte@Sun.COM #include <ima.h>
4910156SZhang.Yi@Sun.COM #include <libsun_ima.h>
507836SJohn.Forte@Sun.COM 
517836SJohn.Forte@Sun.COM #define	LIBRARY_PROPERTY_IMPLEMENTATION_VERSION	L"1.0.0"
527836SJohn.Forte@Sun.COM #define	LIBRARY_PROPERTY_VENDOR			L"Sun Microsystems, Inc."
537836SJohn.Forte@Sun.COM #define	OS_DEVICE_NAME 				"/devices/iscsi"
547836SJohn.Forte@Sun.COM #define	LIBRARY_FILE_NAME			L"libsun_ima.so"
557836SJohn.Forte@Sun.COM 
567836SJohn.Forte@Sun.COM #define	OS_DEVICE_NAME_LEN		256
577836SJohn.Forte@Sun.COM #define	USCSI_TIMEOUT_IN_SEC		10
587836SJohn.Forte@Sun.COM #define	MAX_AUTHMETHODS			10
597836SJohn.Forte@Sun.COM #define	NUM_SUPPORTED_AUTH_METHODS	2
607836SJohn.Forte@Sun.COM #define	SUN_IMA_MAX_DIGEST_ALGORITHMS	2	/* NONE and CRC 32 */
617836SJohn.Forte@Sun.COM #define	SUN_IMA_IP_ADDRESS_LEN		256
627836SJohn.Forte@Sun.COM #define	SUN_IMA_IP_PORT_LEN		64
637836SJohn.Forte@Sun.COM #define	SUN_IMA_MAX_RADIUS_SECRET_LEN	128
6410156SZhang.Yi@Sun.COM #define	MAX_LONG_LONG_STRING_LEN	10
6511271SMilos.Muzik@Sun.COM #define	MAX_INQUIRY_BUFFER_LEN		0xffff
6611271SMilos.Muzik@Sun.COM #define	MAX_REPORT_LUNS_BUFFER_LEN	0xffffffff
6711271SMilos.Muzik@Sun.COM #define	MAX_READ_CAPACITY16_BUFFER_LEN	0xffffffff
687836SJohn.Forte@Sun.COM 
697836SJohn.Forte@Sun.COM /* Forward declaration */
707836SJohn.Forte@Sun.COM #define	BOOL_PARAM			1
717836SJohn.Forte@Sun.COM #define	MIN_MAX_PARAM			2
727836SJohn.Forte@Sun.COM 
737836SJohn.Forte@Sun.COM /* OK */
747836SJohn.Forte@Sun.COM #define	DISC_ADDR_OK			0
757836SJohn.Forte@Sun.COM /* Incorrect IP address */
767836SJohn.Forte@Sun.COM #define	DISC_ADDR_INTEGRITY_ERROR   	1
777836SJohn.Forte@Sun.COM /* Error converting text IP address to numeric binary form */
787836SJohn.Forte@Sun.COM #define	DISC_ADDR_IP_CONV_ERROR		2
797836SJohn.Forte@Sun.COM 
807836SJohn.Forte@Sun.COM /* Currently not defined in  IMA_TARGET_DISCOVERY_METHOD enum */
817836SJohn.Forte@Sun.COM #define	IMA_TARGET_DISCOVERY_METHOD_UNKNOWN  0
827836SJohn.Forte@Sun.COM 
837836SJohn.Forte@Sun.COM static IMA_OID		lhbaObjectId;
847836SJohn.Forte@Sun.COM static IMA_UINT32	pluginOwnerId;
857836SJohn.Forte@Sun.COM static sysevent_handle_t *shp;
867836SJohn.Forte@Sun.COM 
877836SJohn.Forte@Sun.COM 
887836SJohn.Forte@Sun.COM 
897836SJohn.Forte@Sun.COM /*
907836SJohn.Forte@Sun.COM  * Custom struct to allow tgpt to be specified.
917836SJohn.Forte@Sun.COM  */
927836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDRESS_KEY
937836SJohn.Forte@Sun.COM {
947836SJohn.Forte@Sun.COM 	IMA_NODE_NAME name;
957836SJohn.Forte@Sun.COM 	IMA_ADDRESS_KEY	address;
967836SJohn.Forte@Sun.COM 	IMA_UINT16 tpgt;
977836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDRESS_KEY;
987836SJohn.Forte@Sun.COM 
997836SJohn.Forte@Sun.COM /*
1007836SJohn.Forte@Sun.COM  * Custom struct to allow tgpt to be specified.
1017836SJohn.Forte@Sun.COM  */
1027836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES
1037836SJohn.Forte@Sun.COM {
1047836SJohn.Forte@Sun.COM 	IMA_UINT keyCount;
1057836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDRESS_KEY keys[1];
1067836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES;
1077836SJohn.Forte@Sun.COM 
1087836SJohn.Forte@Sun.COM /*
1097836SJohn.Forte@Sun.COM  * Custom struct to allow tgpt to be specified.
1107836SJohn.Forte@Sun.COM  */
1117836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDR_PROP_LIST
1127836SJohn.Forte@Sun.COM {
1137836SJohn.Forte@Sun.COM 	IMA_UINT discAddrCount;
1147836SJohn.Forte@Sun.COM 	IMA_DISCOVERY_ADDRESS_PROPERTIES props[1];
1157836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDR_PROP_LIST;
1167836SJohn.Forte@Sun.COM 
1177836SJohn.Forte@Sun.COM 
1187836SJohn.Forte@Sun.COM static IMA_OBJECT_VISIBILITY_FN pObjectVisibilityCallback = NULL;
1197836SJohn.Forte@Sun.COM static IMA_OBJECT_PROPERTY_FN pObjectPropertyCallback = NULL;
1207836SJohn.Forte@Sun.COM 
1217836SJohn.Forte@Sun.COM static IMA_STATUS getISCSINodeParameter(int paramType, IMA_OID *oid,
1227836SJohn.Forte@Sun.COM     void *pProps, uint32_t paramIndex);
1237836SJohn.Forte@Sun.COM static IMA_STATUS setISCSINodeParameter(int paramType, IMA_OID *oid,
1247836SJohn.Forte@Sun.COM     void *pProps, uint32_t paramIndex);
1257836SJohn.Forte@Sun.COM static IMA_STATUS setAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount,
1267836SJohn.Forte@Sun.COM     const IMA_AUTHMETHOD *pMethodList);
1277836SJohn.Forte@Sun.COM static IMA_STATUS getAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount,
1287836SJohn.Forte@Sun.COM     IMA_AUTHMETHOD *pMethodList);
1297836SJohn.Forte@Sun.COM 
1307836SJohn.Forte@Sun.COM static int prepare_discovery_entry(IMA_TARGET_ADDRESS discoveryAddress,
1317836SJohn.Forte@Sun.COM     entry_t *entry);
1327836SJohn.Forte@Sun.COM static IMA_STATUS configure_discovery_method(IMA_BOOL enable,
1337836SJohn.Forte@Sun.COM     iSCSIDiscoveryMethod_t method);
1347836SJohn.Forte@Sun.COM static IMA_STATUS get_target_oid_list(uint32_t targetListType,
1357836SJohn.Forte@Sun.COM     IMA_OID_LIST **ppList);
1367836SJohn.Forte@Sun.COM static IMA_STATUS get_target_lun_oid_list(IMA_OID * targetOid,
1377836SJohn.Forte@Sun.COM 		iscsi_lun_list_t  **ppLunList);
1387836SJohn.Forte@Sun.COM static int get_lun_devlink(di_devlink_t link, void *osDeviceName);
1397836SJohn.Forte@Sun.COM static IMA_STATUS getDiscoveryAddressPropertiesList(
1407836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDR_PROP_LIST **ppList
1417836SJohn.Forte@Sun.COM );
1427836SJohn.Forte@Sun.COM static IMA_STATUS sendTargets(IMA_TARGET_ADDRESS address,
1437836SJohn.Forte@Sun.COM     SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList
1447836SJohn.Forte@Sun.COM );
1457836SJohn.Forte@Sun.COM 
1467836SJohn.Forte@Sun.COM static IMA_STATUS getSupportedAuthMethods(IMA_OID lhbaOid,
1477836SJohn.Forte@Sun.COM     IMA_BOOL getSettableMethods, IMA_UINT *pMethodCount,
1487836SJohn.Forte@Sun.COM     IMA_AUTHMETHOD *pMethodList);
1497836SJohn.Forte@Sun.COM static IMA_STATUS getLuProperties(IMA_OID luId, IMA_LU_PROPERTIES *pProps);
1507836SJohn.Forte@Sun.COM static IMA_STATUS getTargetProperties(IMA_OID targetId,
1517836SJohn.Forte@Sun.COM     IMA_TARGET_PROPERTIES *pProps);
1527836SJohn.Forte@Sun.COM 
1537836SJohn.Forte@Sun.COM void InitLibrary();
1547836SJohn.Forte@Sun.COM 
libSwprintf(wchar_t * wcs,const wchar_t * lpszFormat,...)1557836SJohn.Forte@Sun.COM static void libSwprintf(wchar_t *wcs, const wchar_t *lpszFormat, ...)
1567836SJohn.Forte@Sun.COM {
1577836SJohn.Forte@Sun.COM 	va_list args;
1587836SJohn.Forte@Sun.COM 	va_start(args, lpszFormat);
1597836SJohn.Forte@Sun.COM 	(void) vswprintf(wcs, OS_DEVICE_NAME_LEN - 1, lpszFormat, args);
1607836SJohn.Forte@Sun.COM 	va_end(args);
1617836SJohn.Forte@Sun.COM }
1627836SJohn.Forte@Sun.COM 
1637836SJohn.Forte@Sun.COM static void
sysevent_handler(sysevent_t * ev)1647836SJohn.Forte@Sun.COM sysevent_handler(sysevent_t *ev)
1657836SJohn.Forte@Sun.COM {
1667836SJohn.Forte@Sun.COM 	IMA_OID tmpOid;
1677836SJohn.Forte@Sun.COM 	IMA_BOOL becomingVisible = IMA_FALSE;
1687836SJohn.Forte@Sun.COM 	IMA_UINT i;
1697836SJohn.Forte@Sun.COM 
1707836SJohn.Forte@Sun.COM 	const char *visibility_subclasses[] = {
1717836SJohn.Forte@Sun.COM 		ESC_ISCSI_STATIC_START,
1727836SJohn.Forte@Sun.COM 		ESC_ISCSI_STATIC_END,
1737836SJohn.Forte@Sun.COM 		ESC_ISCSI_SEND_TARGETS_START,
1747836SJohn.Forte@Sun.COM 		ESC_ISCSI_SEND_TARGETS_END,
1757836SJohn.Forte@Sun.COM 		ESC_ISCSI_SLP_START,
1767836SJohn.Forte@Sun.COM 		ESC_ISCSI_SLP_END,
1777836SJohn.Forte@Sun.COM 		ESC_ISCSI_ISNS_START,
1787836SJohn.Forte@Sun.COM 		ESC_ISCSI_ISNS_END,
1797836SJohn.Forte@Sun.COM 		NULL
1807836SJohn.Forte@Sun.COM 	};
1817836SJohn.Forte@Sun.COM 
1827836SJohn.Forte@Sun.COM 	tmpOid.ownerId = pluginOwnerId;
1837836SJohn.Forte@Sun.COM 	tmpOid.objectType = IMA_OBJECT_TYPE_TARGET;
1847836SJohn.Forte@Sun.COM 	tmpOid.objectSequenceNumber = 0;
1857836SJohn.Forte@Sun.COM 
1867836SJohn.Forte@Sun.COM 	/* Make sure our event class matches what we are looking for */
1877836SJohn.Forte@Sun.COM 	if (strncmp(EC_ISCSI, sysevent_get_class_name(ev),
1887836SJohn.Forte@Sun.COM 	    strlen(EC_ISCSI)) != 0) {
1897836SJohn.Forte@Sun.COM 		return;
1907836SJohn.Forte@Sun.COM 	}
1917836SJohn.Forte@Sun.COM 
1927836SJohn.Forte@Sun.COM 
1937836SJohn.Forte@Sun.COM 	/* Check for object property changes */
1947836SJohn.Forte@Sun.COM 	if ((strncmp(ESC_ISCSI_PROP_CHANGE,
1957836SJohn.Forte@Sun.COM 	    sysevent_get_subclass_name(ev),
1967836SJohn.Forte@Sun.COM 	    strlen(ESC_ISCSI_PROP_CHANGE)) == 0)) {
1977836SJohn.Forte@Sun.COM 		if (pObjectPropertyCallback != NULL)
1987836SJohn.Forte@Sun.COM 			pObjectPropertyCallback(tmpOid);
1997836SJohn.Forte@Sun.COM 	} else {
2007836SJohn.Forte@Sun.COM 		i = 0;
2017836SJohn.Forte@Sun.COM 		while (visibility_subclasses[i] != NULL) {
2027836SJohn.Forte@Sun.COM 			if ((strncmp(visibility_subclasses[i],
2037836SJohn.Forte@Sun.COM 			    sysevent_get_subclass_name(ev),
2047836SJohn.Forte@Sun.COM 			    strlen(visibility_subclasses[i])) == 0) &&
2057836SJohn.Forte@Sun.COM 			    pObjectVisibilityCallback != NULL) {
2067836SJohn.Forte@Sun.COM 				becomingVisible = IMA_TRUE;
2077836SJohn.Forte@Sun.COM 				pObjectVisibilityCallback(becomingVisible,
2087836SJohn.Forte@Sun.COM 				    tmpOid);
2097836SJohn.Forte@Sun.COM 			}
2107836SJohn.Forte@Sun.COM 			i++;
2117836SJohn.Forte@Sun.COM 		}
2127836SJohn.Forte@Sun.COM 	}
2137836SJohn.Forte@Sun.COM }
2147836SJohn.Forte@Sun.COM 
init_sysevents()2157836SJohn.Forte@Sun.COM IMA_STATUS init_sysevents() {
2167836SJohn.Forte@Sun.COM 	const char *subclass_list[] = {
2177836SJohn.Forte@Sun.COM 		ESC_ISCSI_STATIC_START,
2187836SJohn.Forte@Sun.COM 		ESC_ISCSI_STATIC_END,
2197836SJohn.Forte@Sun.COM 		ESC_ISCSI_SEND_TARGETS_START,
2207836SJohn.Forte@Sun.COM 		ESC_ISCSI_SEND_TARGETS_END,
2217836SJohn.Forte@Sun.COM 		ESC_ISCSI_SLP_START,
2227836SJohn.Forte@Sun.COM 		ESC_ISCSI_SLP_END,
2237836SJohn.Forte@Sun.COM 		ESC_ISCSI_ISNS_START,
2247836SJohn.Forte@Sun.COM 		ESC_ISCSI_ISNS_END,
2257836SJohn.Forte@Sun.COM 		ESC_ISCSI_PROP_CHANGE,
2267836SJohn.Forte@Sun.COM 	};
2277836SJohn.Forte@Sun.COM 
2287836SJohn.Forte@Sun.COM 	/* Bind event handler and create subscriber handle */
2297836SJohn.Forte@Sun.COM 	shp = sysevent_bind_handle(sysevent_handler);
2307836SJohn.Forte@Sun.COM 	if (shp == NULL) {
2317836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2327836SJohn.Forte@Sun.COM 	}
2337836SJohn.Forte@Sun.COM 
2347836SJohn.Forte@Sun.COM 	if (sysevent_subscribe_event(shp, EC_ISCSI, subclass_list, 9) != 0) {
2357836SJohn.Forte@Sun.COM 		sysevent_unbind_handle(shp);
2367836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2377836SJohn.Forte@Sun.COM 	}
2387836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
2397836SJohn.Forte@Sun.COM }
2407836SJohn.Forte@Sun.COM 
Initialize(IMA_UINT32 pluginOid)2417836SJohn.Forte@Sun.COM IMA_STATUS Initialize(IMA_UINT32 pluginOid) {
2427836SJohn.Forte@Sun.COM 	pluginOwnerId = pluginOid;
2437836SJohn.Forte@Sun.COM 	return (init_sysevents());
2447836SJohn.Forte@Sun.COM }
2457836SJohn.Forte@Sun.COM 
Terminate()2467836SJohn.Forte@Sun.COM void Terminate() {
2477836SJohn.Forte@Sun.COM 	if (shp != NULL) {
2487836SJohn.Forte@Sun.COM 		sysevent_unsubscribe_event(shp, EC_ISCSI);
2497836SJohn.Forte@Sun.COM 	}
2507836SJohn.Forte@Sun.COM 
2517836SJohn.Forte@Sun.COM }
2527836SJohn.Forte@Sun.COM 
InitLibrary()2537836SJohn.Forte@Sun.COM void InitLibrary() {
2547836SJohn.Forte@Sun.COM }
2557836SJohn.Forte@Sun.COM 
GetBuildTime(IMA_DATETIME * pdatetime)2567836SJohn.Forte@Sun.COM static void GetBuildTime(IMA_DATETIME* pdatetime)
2577836SJohn.Forte@Sun.COM {
2587836SJohn.Forte@Sun.COM 	(void) memset(pdatetime, 0, sizeof (IMA_DATETIME));
2597836SJohn.Forte@Sun.COM }
2607836SJohn.Forte@Sun.COM 
2617836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetNodeProperties(IMA_OID nodeOid,IMA_NODE_PROPERTIES * pProps)2627836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNodeProperties(
2637836SJohn.Forte@Sun.COM 	IMA_OID nodeOid,
2647836SJohn.Forte@Sun.COM 	IMA_NODE_PROPERTIES *pProps
2657836SJohn.Forte@Sun.COM )
2667836SJohn.Forte@Sun.COM {
2677836SJohn.Forte@Sun.COM 	int fd;
2687836SJohn.Forte@Sun.COM 	iscsi_param_get_t pg;
2697836SJohn.Forte@Sun.COM 
2707836SJohn.Forte@Sun.COM 	pProps->runningInInitiatorMode = IMA_TRUE;
2717836SJohn.Forte@Sun.COM 	pProps->runningInTargetMode = IMA_FALSE;
2727836SJohn.Forte@Sun.COM 	pProps->nameAndAliasSettable = IMA_FALSE;
2737836SJohn.Forte@Sun.COM 
2747836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2757836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2767836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
2777836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2787836SJohn.Forte@Sun.COM 	}
2797836SJohn.Forte@Sun.COM 
2807836SJohn.Forte@Sun.COM 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
2817836SJohn.Forte@Sun.COM 	pg.g_vers = ISCSI_INTERFACE_VERSION;
2827836SJohn.Forte@Sun.COM 	pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME;
2837836SJohn.Forte@Sun.COM 
2847836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) {
2857836SJohn.Forte@Sun.COM 		pProps->nameValid = IMA_FALSE;
2867836SJohn.Forte@Sun.COM 	} else {
2877836SJohn.Forte@Sun.COM 		if (strlen((char *)pg.g_value.v_name) > 0) {
2887836SJohn.Forte@Sun.COM 			(void) mbstowcs(pProps->name,
2897836SJohn.Forte@Sun.COM 			    (char *)pg.g_value.v_name,
2907836SJohn.Forte@Sun.COM 			    IMA_NODE_NAME_LEN);
2917836SJohn.Forte@Sun.COM 			pProps->nameValid = IMA_TRUE;
2927836SJohn.Forte@Sun.COM 		} else {
2937836SJohn.Forte@Sun.COM 			pProps->nameValid = IMA_FALSE;
2947836SJohn.Forte@Sun.COM 		}
2957836SJohn.Forte@Sun.COM 	}
2967836SJohn.Forte@Sun.COM 
2977836SJohn.Forte@Sun.COM 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
2987836SJohn.Forte@Sun.COM 	pg.g_vers = ISCSI_INTERFACE_VERSION;
2997836SJohn.Forte@Sun.COM 	pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS;
3007836SJohn.Forte@Sun.COM 	(void) memset(pProps->alias, 0,
3017836SJohn.Forte@Sun.COM 	    sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN);
3027836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) {
3037836SJohn.Forte@Sun.COM 		pProps->aliasValid = IMA_FALSE;
3047836SJohn.Forte@Sun.COM 	} else {
3057836SJohn.Forte@Sun.COM 		if (strlen((char *)pg.g_value.v_name) > 0) {
3067836SJohn.Forte@Sun.COM 			(void) mbstowcs(pProps->alias,
3077836SJohn.Forte@Sun.COM 			    (char *)pg.g_value.v_name,
3087836SJohn.Forte@Sun.COM 			    IMA_NODE_ALIAS_LEN);
3097836SJohn.Forte@Sun.COM 			pProps->aliasValid = IMA_TRUE;
3107836SJohn.Forte@Sun.COM 		}
3117836SJohn.Forte@Sun.COM 	}
3127836SJohn.Forte@Sun.COM 
3137836SJohn.Forte@Sun.COM 	(void) close(fd);
3147836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
3157836SJohn.Forte@Sun.COM }
3167836SJohn.Forte@Sun.COM 
IMA_SetNodeName(IMA_OID nodeOid,const IMA_NODE_NAME newName)3177836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNodeName(
3187836SJohn.Forte@Sun.COM 	IMA_OID nodeOid,
3197836SJohn.Forte@Sun.COM 	const IMA_NODE_NAME newName
3207836SJohn.Forte@Sun.COM )
3217836SJohn.Forte@Sun.COM {
3227836SJohn.Forte@Sun.COM 	int fd;
3237836SJohn.Forte@Sun.COM 	iscsi_param_set_t ps;
3247836SJohn.Forte@Sun.COM 
3257836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3267836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3277836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
3287836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3297836SJohn.Forte@Sun.COM 	}
3307836SJohn.Forte@Sun.COM 
3317836SJohn.Forte@Sun.COM 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
3327836SJohn.Forte@Sun.COM 	ps.s_oid = nodeOid.objectSequenceNumber;
3337836SJohn.Forte@Sun.COM 	ps.s_vers = ISCSI_INTERFACE_VERSION;
3347836SJohn.Forte@Sun.COM 	ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME;
3357836SJohn.Forte@Sun.COM 	(void) wcstombs((char *)ps.s_value.v_name, newName, ISCSI_MAX_NAME_LEN);
3367836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_INIT_NODE_NAME_SET, &ps)) {
3377836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
3387836SJohn.Forte@Sun.COM 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
3397836SJohn.Forte@Sun.COM 		(void) close(fd);
3407836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3417836SJohn.Forte@Sun.COM 	}
3427836SJohn.Forte@Sun.COM 
3437836SJohn.Forte@Sun.COM 	(void) close(fd);
3447836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
3457836SJohn.Forte@Sun.COM }
3467836SJohn.Forte@Sun.COM 
IMA_SetNodeAlias(IMA_OID nodeOid,const IMA_NODE_ALIAS newAlias)3477836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNodeAlias(
3487836SJohn.Forte@Sun.COM 	IMA_OID nodeOid,
3497836SJohn.Forte@Sun.COM 	const IMA_NODE_ALIAS newAlias
3507836SJohn.Forte@Sun.COM )
3517836SJohn.Forte@Sun.COM {
3527836SJohn.Forte@Sun.COM 	int fd;
3537836SJohn.Forte@Sun.COM 	iscsi_param_set_t ps;
3547836SJohn.Forte@Sun.COM 
3557836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3567836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3577836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
3587836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3597836SJohn.Forte@Sun.COM 	}
3607836SJohn.Forte@Sun.COM 
3617836SJohn.Forte@Sun.COM 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
3627836SJohn.Forte@Sun.COM 	ps.s_oid = nodeOid.objectSequenceNumber;
3637836SJohn.Forte@Sun.COM 	ps.s_vers = ISCSI_INTERFACE_VERSION;
3647836SJohn.Forte@Sun.COM 	ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS;
3657836SJohn.Forte@Sun.COM 
3667836SJohn.Forte@Sun.COM 	/* newAlias = NULL specifies that the alias should be deleted. */
3677836SJohn.Forte@Sun.COM 	if (newAlias != NULL)
3687836SJohn.Forte@Sun.COM 		(void) wcstombs((char *)ps.s_value.v_name, newAlias,
3697836SJohn.Forte@Sun.COM 		    ISCSI_MAX_NAME_LEN);
3707836SJohn.Forte@Sun.COM 	else
3717836SJohn.Forte@Sun.COM 		(void) wcstombs((char *)ps.s_value.v_name,
3727836SJohn.Forte@Sun.COM 		    L"", ISCSI_MAX_NAME_LEN);
3737836SJohn.Forte@Sun.COM 
3747836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_PARAM_SET, &ps)) {
3757836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
3767836SJohn.Forte@Sun.COM 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
3777836SJohn.Forte@Sun.COM 		(void) close(fd);
3787836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3797836SJohn.Forte@Sun.COM 	}
3807836SJohn.Forte@Sun.COM 
3817836SJohn.Forte@Sun.COM 	(void) close(fd);
3827836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
3837836SJohn.Forte@Sun.COM }
3847836SJohn.Forte@Sun.COM 
3857836SJohn.Forte@Sun.COM 
IMA_GetLhbaOidList(IMA_OID_LIST ** ppList)3867836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLhbaOidList(
3877836SJohn.Forte@Sun.COM 	IMA_OID_LIST **ppList
3887836SJohn.Forte@Sun.COM )
3897836SJohn.Forte@Sun.COM {
3907836SJohn.Forte@Sun.COM 	/* Always return the same object ID for the lhba */
3917836SJohn.Forte@Sun.COM 	lhbaObjectId.objectType = IMA_OBJECT_TYPE_LHBA;
3927836SJohn.Forte@Sun.COM 	lhbaObjectId.ownerId = pluginOwnerId;
3937836SJohn.Forte@Sun.COM 	lhbaObjectId.objectSequenceNumber = ISCSI_INITIATOR_OID;
3947836SJohn.Forte@Sun.COM 
3957836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST));
3967836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
3977836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3987836SJohn.Forte@Sun.COM 	}
3997836SJohn.Forte@Sun.COM 
4007836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = 1;
4017836SJohn.Forte@Sun.COM 	(void) memcpy(&(*ppList)->oids[0],
4027836SJohn.Forte@Sun.COM 	    &lhbaObjectId, sizeof (lhbaObjectId));
4037836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
4047836SJohn.Forte@Sun.COM }
4057836SJohn.Forte@Sun.COM 
4067836SJohn.Forte@Sun.COM 
4077836SJohn.Forte@Sun.COM /*
4087836SJohn.Forte@Sun.COM  * Get the discovery properties of the LHBA
4097836SJohn.Forte@Sun.COM  */
4107836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetDiscoveryProperties(IMA_OID oid,IMA_DISCOVERY_PROPERTIES * pProps)4117836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDiscoveryProperties(
4127836SJohn.Forte@Sun.COM 	IMA_OID oid,
4137836SJohn.Forte@Sun.COM 	IMA_DISCOVERY_PROPERTIES *pProps
4147836SJohn.Forte@Sun.COM )
4157836SJohn.Forte@Sun.COM {
4167836SJohn.Forte@Sun.COM 	int fd;
4177836SJohn.Forte@Sun.COM 	iSCSIDiscoveryProperties_t discoveryProps;
4187836SJohn.Forte@Sun.COM 
4197836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
4207836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
4217836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
4227836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
4237836SJohn.Forte@Sun.COM 	}
4247836SJohn.Forte@Sun.COM 
4257836SJohn.Forte@Sun.COM 	(void) memset(&discoveryProps, 0, sizeof (discoveryProps));
4267836SJohn.Forte@Sun.COM 	discoveryProps.vers = ISCSI_INTERFACE_VERSION;
4277836SJohn.Forte@Sun.COM 
4287836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_PROPS, &discoveryProps) != 0) {
4297836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
4307836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_PROPS ioctl failed, errno: %d", errno);
4317836SJohn.Forte@Sun.COM 		(void) close(fd);
4327836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
4337836SJohn.Forte@Sun.COM 	}
4347836SJohn.Forte@Sun.COM 
4357836SJohn.Forte@Sun.COM 	pProps->iSnsDiscoverySettable = discoveryProps.iSNSDiscoverySettable;
4367836SJohn.Forte@Sun.COM 	pProps->iSnsDiscoveryEnabled = discoveryProps.iSNSDiscoveryEnabled;
4377836SJohn.Forte@Sun.COM 	/*
4387836SJohn.Forte@Sun.COM 	 * Set the iSNS discovery method - The IMA specification indicates
4397836SJohn.Forte@Sun.COM 	 * this field is valid only if iSNS discovery is enabled.
4407836SJohn.Forte@Sun.COM 	 */
4417836SJohn.Forte@Sun.COM 	if (pProps->iSnsDiscoveryEnabled == IMA_TRUE) {
4427836SJohn.Forte@Sun.COM 		switch (discoveryProps.iSNSDiscoveryMethod) {
4437836SJohn.Forte@Sun.COM 			case iSNSDiscoveryMethodStatic:
4447836SJohn.Forte@Sun.COM 				pProps->iSnsDiscoveryMethod =
4457836SJohn.Forte@Sun.COM 				    IMA_ISNS_DISCOVERY_METHOD_STATIC;
4467836SJohn.Forte@Sun.COM 				break;
4477836SJohn.Forte@Sun.COM 			case iSNSDiscoveryMethodDHCP:
4487836SJohn.Forte@Sun.COM 				pProps->iSnsDiscoveryMethod =
4497836SJohn.Forte@Sun.COM 				    IMA_ISNS_DISCOVERY_METHOD_DHCP;
4507836SJohn.Forte@Sun.COM 				break;
4517836SJohn.Forte@Sun.COM 			case iSNSDiscoveryMethodSLP:
4527836SJohn.Forte@Sun.COM 				pProps->iSnsDiscoveryMethod =
4537836SJohn.Forte@Sun.COM 				    IMA_ISNS_DISCOVERY_METHOD_SLP;
4547836SJohn.Forte@Sun.COM 				break;
4557836SJohn.Forte@Sun.COM 			default:
4567836SJohn.Forte@Sun.COM 				(void) close(fd);
4577836SJohn.Forte@Sun.COM 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
4587836SJohn.Forte@Sun.COM 		}
4597836SJohn.Forte@Sun.COM 	}
4607836SJohn.Forte@Sun.COM 	(void) memcpy(pProps->iSnsHost.id.hostname,
4617836SJohn.Forte@Sun.COM 	    discoveryProps.iSNSDomainName,
4627836SJohn.Forte@Sun.COM 	    sizeof (pProps->iSnsHost.id.hostname));
4637836SJohn.Forte@Sun.COM 	pProps->slpDiscoverySettable = discoveryProps.SLPDiscoverySettable;
4647836SJohn.Forte@Sun.COM 	pProps->slpDiscoveryEnabled = discoveryProps.SLPDiscoveryEnabled;
4657836SJohn.Forte@Sun.COM 	pProps->staticDiscoverySettable =
4667836SJohn.Forte@Sun.COM 	    discoveryProps.StaticDiscoverySettable;
4677836SJohn.Forte@Sun.COM 	pProps->staticDiscoveryEnabled = discoveryProps.StaticDiscoveryEnabled;
4687836SJohn.Forte@Sun.COM 	pProps->sendTargetsDiscoverySettable =
4697836SJohn.Forte@Sun.COM 	    discoveryProps.SendTargetsDiscoverySettable;
4707836SJohn.Forte@Sun.COM 	pProps->sendTargetsDiscoveryEnabled =
4717836SJohn.Forte@Sun.COM 	    discoveryProps.SendTargetsDiscoveryEnabled;
4727836SJohn.Forte@Sun.COM 
4737836SJohn.Forte@Sun.COM 	(void) close(fd);
4747836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
4757836SJohn.Forte@Sun.COM }
4767836SJohn.Forte@Sun.COM 
IMA_FreeMemory(void * pMemory)4777836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_FreeMemory(
4787836SJohn.Forte@Sun.COM 	void *pMemory
4797836SJohn.Forte@Sun.COM )
4807836SJohn.Forte@Sun.COM {
4817836SJohn.Forte@Sun.COM 	if (pMemory != NULL)
4827836SJohn.Forte@Sun.COM 		free(pMemory);
4837836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
4847836SJohn.Forte@Sun.COM }
4857836SJohn.Forte@Sun.COM 
IMA_GetNonSharedNodeOidList(IMA_OID_LIST ** ppList)4867836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNonSharedNodeOidList(
4877836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
4887836SJohn.Forte@Sun.COM )
4897836SJohn.Forte@Sun.COM {
4907836SJohn.Forte@Sun.COM 	if (ppList == NULL)
4917836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
4927836SJohn.Forte@Sun.COM 
4937836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST*) calloc(1, sizeof (IMA_OID_LIST));
4947836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
4957836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
4967836SJohn.Forte@Sun.COM 	}
4977836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = 0;
4987836SJohn.Forte@Sun.COM 
4997836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
5007836SJohn.Forte@Sun.COM }
5017836SJohn.Forte@Sun.COM 
IMA_GetFirstBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)5027836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetFirstBurstLengthProperties(
5037836SJohn.Forte@Sun.COM 		IMA_OID Oid,
5047836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
5057836SJohn.Forte@Sun.COM )
5067836SJohn.Forte@Sun.COM {
5077836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
5087836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH));
5097836SJohn.Forte@Sun.COM }
5107836SJohn.Forte@Sun.COM 
IMA_GetMaxBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)5117836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxBurstLengthProperties(
5127836SJohn.Forte@Sun.COM 		IMA_OID Oid,
5137836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
5147836SJohn.Forte@Sun.COM )
5157836SJohn.Forte@Sun.COM {
5167836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
5177836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH));
5187836SJohn.Forte@Sun.COM }
5197836SJohn.Forte@Sun.COM 
IMA_GetMaxRecvDataSegmentLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)5207836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxRecvDataSegmentLengthProperties(
5217836SJohn.Forte@Sun.COM 		IMA_OID Oid,
5227836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
5237836SJohn.Forte@Sun.COM )
5247836SJohn.Forte@Sun.COM {
5257836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
5267836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH));
5277836SJohn.Forte@Sun.COM }
5287836SJohn.Forte@Sun.COM 
5297836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_PluginIOCtl(IMA_OID pluginOid,IMA_UINT command,const void * pInputBuffer,IMA_UINT inputBufferLength,void * pOutputBuffer,IMA_UINT * pOutputBufferLength)5307836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_PluginIOCtl(
5317836SJohn.Forte@Sun.COM 		IMA_OID pluginOid,
5327836SJohn.Forte@Sun.COM 		IMA_UINT command,
5337836SJohn.Forte@Sun.COM 		const void *pInputBuffer,
5347836SJohn.Forte@Sun.COM 		IMA_UINT inputBufferLength,
5357836SJohn.Forte@Sun.COM 		void *pOutputBuffer,
5367836SJohn.Forte@Sun.COM 		IMA_UINT *pOutputBufferLength
5377836SJohn.Forte@Sun.COM )
5387836SJohn.Forte@Sun.COM {
5397836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
5407836SJohn.Forte@Sun.COM }
5417836SJohn.Forte@Sun.COM 
IMA_SetFirstBurstLength(IMA_OID lhbaId,IMA_UINT firstBurstLength)5427836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetFirstBurstLength(
5437836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
5447836SJohn.Forte@Sun.COM 		IMA_UINT firstBurstLength
5457836SJohn.Forte@Sun.COM )
5467836SJohn.Forte@Sun.COM {
5477836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
5487836SJohn.Forte@Sun.COM 
5497836SJohn.Forte@Sun.COM 	mv.currentValue = firstBurstLength;
5507836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
5517836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH));
5527836SJohn.Forte@Sun.COM }
5537836SJohn.Forte@Sun.COM 
IMA_SetMaxBurstLength(IMA_OID lhbaId,IMA_UINT maxBurstLength)5547836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetMaxBurstLength(
5557836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
5567836SJohn.Forte@Sun.COM 		IMA_UINT maxBurstLength
5577836SJohn.Forte@Sun.COM )
5587836SJohn.Forte@Sun.COM {
5597836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
5607836SJohn.Forte@Sun.COM 
5617836SJohn.Forte@Sun.COM 	mv.currentValue = maxBurstLength;
5627836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
5637836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH));
5647836SJohn.Forte@Sun.COM }
5657836SJohn.Forte@Sun.COM 
IMA_SetMaxRecvDataSegmentLength(IMA_OID lhbaId,IMA_UINT maxRecvDataSegmentLength)5667836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetMaxRecvDataSegmentLength(
5677836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
5687836SJohn.Forte@Sun.COM 		IMA_UINT maxRecvDataSegmentLength
5697836SJohn.Forte@Sun.COM )
5707836SJohn.Forte@Sun.COM {
5717836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
5727836SJohn.Forte@Sun.COM 
5737836SJohn.Forte@Sun.COM 	mv.currentValue = maxRecvDataSegmentLength;
5747836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
5757836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH));
5767836SJohn.Forte@Sun.COM }
5777836SJohn.Forte@Sun.COM 
IMA_GetMaxConnectionsProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)5787836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetMaxConnectionsProperties(
5797836SJohn.Forte@Sun.COM 		IMA_OID Oid,
5807836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
5817836SJohn.Forte@Sun.COM )
5827836SJohn.Forte@Sun.COM {
5837836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
5847836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_CONNECTIONS));
5857836SJohn.Forte@Sun.COM }
5867836SJohn.Forte@Sun.COM 
IMA_SetMaxConnections(IMA_OID lhbaId,IMA_UINT maxConnections)5877836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetMaxConnections(
5887836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
5897836SJohn.Forte@Sun.COM 		IMA_UINT maxConnections
5907836SJohn.Forte@Sun.COM )
5917836SJohn.Forte@Sun.COM {
5927836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
5937836SJohn.Forte@Sun.COM 
5947836SJohn.Forte@Sun.COM 	mv.currentValue = maxConnections;
5957836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
5967836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_MAX_CONNECTIONS));
5977836SJohn.Forte@Sun.COM }
5987836SJohn.Forte@Sun.COM 
IMA_GetDefaultTime2RetainProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)5997836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDefaultTime2RetainProperties(
6007836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
6017836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
6027836SJohn.Forte@Sun.COM )
6037836SJohn.Forte@Sun.COM {
6047836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps,
6057836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN));
6067836SJohn.Forte@Sun.COM }
6077836SJohn.Forte@Sun.COM 
IMA_SetDefaultTime2Retain(IMA_OID lhbaId,IMA_UINT defaultTime2Retain)6087836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetDefaultTime2Retain(
6097836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
6107836SJohn.Forte@Sun.COM 		IMA_UINT defaultTime2Retain
6117836SJohn.Forte@Sun.COM )
6127836SJohn.Forte@Sun.COM {
6137836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
6147836SJohn.Forte@Sun.COM 
6157836SJohn.Forte@Sun.COM 	mv.currentValue = defaultTime2Retain;
6167836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
6177836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN));
6187836SJohn.Forte@Sun.COM }
6197836SJohn.Forte@Sun.COM 
IMA_GetDefaultTime2WaitProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)6207836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDefaultTime2WaitProperties(
6217836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
6227836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
6237836SJohn.Forte@Sun.COM )
6247836SJohn.Forte@Sun.COM {
6257836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps,
6267836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT));
6277836SJohn.Forte@Sun.COM }
6287836SJohn.Forte@Sun.COM 
IMA_SetDefaultTime2Wait(IMA_OID lhbaId,IMA_UINT defaultTime2Wait)6297836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetDefaultTime2Wait(
6307836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
6317836SJohn.Forte@Sun.COM 		IMA_UINT defaultTime2Wait
6327836SJohn.Forte@Sun.COM )
6337836SJohn.Forte@Sun.COM {
6347836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
6357836SJohn.Forte@Sun.COM 
6367836SJohn.Forte@Sun.COM 	mv.currentValue = defaultTime2Wait;
6377836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
6387836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT));
6397836SJohn.Forte@Sun.COM }
6407836SJohn.Forte@Sun.COM 
IMA_GetMaxOutstandingR2TProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)6417836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetMaxOutstandingR2TProperties(
6427836SJohn.Forte@Sun.COM 		IMA_OID Oid,
6437836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
6447836SJohn.Forte@Sun.COM )
6457836SJohn.Forte@Sun.COM {
6467836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
6477836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_OUTSTANDING_R2T));
6487836SJohn.Forte@Sun.COM }
6497836SJohn.Forte@Sun.COM 
IMA_SetMaxOutstandingR2T(IMA_OID lhbaId,IMA_UINT maxOutstandingR2T)6507836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetMaxOutstandingR2T(
6517836SJohn.Forte@Sun.COM 		IMA_OID lhbaId,
6527836SJohn.Forte@Sun.COM 		IMA_UINT maxOutstandingR2T
6537836SJohn.Forte@Sun.COM )
6547836SJohn.Forte@Sun.COM {
6557836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
6567836SJohn.Forte@Sun.COM 
6577836SJohn.Forte@Sun.COM 	mv.currentValue = maxOutstandingR2T;
6587836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
6597836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_OUTSTANDING_R2T));
6607836SJohn.Forte@Sun.COM }
6617836SJohn.Forte@Sun.COM 
6627836SJohn.Forte@Sun.COM 
IMA_GetErrorRecoveryLevelProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)6637836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetErrorRecoveryLevelProperties(
6647836SJohn.Forte@Sun.COM 		IMA_OID Oid,
6657836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *pProps
6667836SJohn.Forte@Sun.COM )
6677836SJohn.Forte@Sun.COM {
6687836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
6697836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL));
6707836SJohn.Forte@Sun.COM }
6717836SJohn.Forte@Sun.COM 
IMA_SetErrorRecoveryLevel(IMA_OID Oid,IMA_UINT errorRecoveryLevel)6727836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetErrorRecoveryLevel(
6737836SJohn.Forte@Sun.COM 		IMA_OID Oid,
6747836SJohn.Forte@Sun.COM 		IMA_UINT errorRecoveryLevel
6757836SJohn.Forte@Sun.COM )
6767836SJohn.Forte@Sun.COM {
6777836SJohn.Forte@Sun.COM 	IMA_MIN_MAX_VALUE mv;
6787836SJohn.Forte@Sun.COM 
6797836SJohn.Forte@Sun.COM 	mv.currentValue = errorRecoveryLevel;
6807836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(MIN_MAX_PARAM, &Oid, &mv,
6817836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL));
6827836SJohn.Forte@Sun.COM }
6837836SJohn.Forte@Sun.COM 
IMA_GetInitialR2TProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)6847836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetInitialR2TProperties(
6857836SJohn.Forte@Sun.COM 		IMA_OID Oid,
6867836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *pProps
6877836SJohn.Forte@Sun.COM )
6887836SJohn.Forte@Sun.COM {
6897836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
6907836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_INITIAL_R2T));
6917836SJohn.Forte@Sun.COM }
6927836SJohn.Forte@Sun.COM 
IMA_SetInitialR2T(IMA_OID Oid,IMA_BOOL initialR2T)6937836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetInitialR2T(
6947836SJohn.Forte@Sun.COM 		IMA_OID Oid,
6957836SJohn.Forte@Sun.COM 		IMA_BOOL initialR2T
6967836SJohn.Forte@Sun.COM )
6977836SJohn.Forte@Sun.COM {
6987836SJohn.Forte@Sun.COM 	IMA_BOOL_VALUE bv;
6997836SJohn.Forte@Sun.COM 
7007836SJohn.Forte@Sun.COM 	bv.currentValue = initialR2T;
7017836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
7027836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_INITIAL_R2T));
7037836SJohn.Forte@Sun.COM }
7047836SJohn.Forte@Sun.COM 
7057836SJohn.Forte@Sun.COM 
IMA_GetImmediateDataProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)7067836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetImmediateDataProperties(
7077836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7087836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *pProps
7097836SJohn.Forte@Sun.COM )
7107836SJohn.Forte@Sun.COM {
7117836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
7127836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_IMMEDIATE_DATA));
7137836SJohn.Forte@Sun.COM }
7147836SJohn.Forte@Sun.COM 
IMA_SetImmediateData(IMA_OID Oid,IMA_BOOL immediateData)7157836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetImmediateData(
7167836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7177836SJohn.Forte@Sun.COM 		IMA_BOOL immediateData
7187836SJohn.Forte@Sun.COM )
7197836SJohn.Forte@Sun.COM {
7207836SJohn.Forte@Sun.COM 	IMA_BOOL_VALUE bv;
7217836SJohn.Forte@Sun.COM 
7227836SJohn.Forte@Sun.COM 	bv.currentValue = immediateData;
7237836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
7247836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_IMMEDIATE_DATA));
7257836SJohn.Forte@Sun.COM }
7267836SJohn.Forte@Sun.COM 
IMA_GetDataPduInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)7277836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDataPduInOrderProperties(
7287836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7297836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *pProps
7307836SJohn.Forte@Sun.COM )
7317836SJohn.Forte@Sun.COM {
7327836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
7337836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER));
7347836SJohn.Forte@Sun.COM }
7357836SJohn.Forte@Sun.COM 
IMA_SetDataPduInOrder(IMA_OID Oid,IMA_BOOL dataPduInOrder)7367836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetDataPduInOrder(
7377836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7387836SJohn.Forte@Sun.COM 		IMA_BOOL dataPduInOrder
7397836SJohn.Forte@Sun.COM )
7407836SJohn.Forte@Sun.COM {
7417836SJohn.Forte@Sun.COM 	IMA_BOOL_VALUE bv;
7427836SJohn.Forte@Sun.COM 
7437836SJohn.Forte@Sun.COM 	bv.currentValue = dataPduInOrder;
7447836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
7457836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER));
7467836SJohn.Forte@Sun.COM }
7477836SJohn.Forte@Sun.COM 
IMA_GetDataSequenceInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)7487836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDataSequenceInOrderProperties(
7497836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7507836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *pProps
7517836SJohn.Forte@Sun.COM )
7527836SJohn.Forte@Sun.COM {
7537836SJohn.Forte@Sun.COM 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
7547836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER));
7557836SJohn.Forte@Sun.COM }
7567836SJohn.Forte@Sun.COM 
IMA_SetDataSequenceInOrder(IMA_OID Oid,IMA_BOOL dataSequenceInOrder)7577836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetDataSequenceInOrder(
7587836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7597836SJohn.Forte@Sun.COM 		IMA_BOOL dataSequenceInOrder
7607836SJohn.Forte@Sun.COM )
7617836SJohn.Forte@Sun.COM {
7627836SJohn.Forte@Sun.COM 	IMA_BOOL_VALUE bv;
7637836SJohn.Forte@Sun.COM 
7647836SJohn.Forte@Sun.COM 	bv.currentValue = dataSequenceInOrder;
7657836SJohn.Forte@Sun.COM 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
7667836SJohn.Forte@Sun.COM 	    ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER));
7677836SJohn.Forte@Sun.COM }
7687836SJohn.Forte@Sun.COM 
7697836SJohn.Forte@Sun.COM 
7707836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_SetStatisticsCollection(IMA_OID Oid,IMA_BOOL enableStatisticsCollection)7717836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetStatisticsCollection(
7727836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7737836SJohn.Forte@Sun.COM 		IMA_BOOL enableStatisticsCollection
7747836SJohn.Forte@Sun.COM )
7757836SJohn.Forte@Sun.COM {
7767836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
7777836SJohn.Forte@Sun.COM }
7787836SJohn.Forte@Sun.COM 
7797836SJohn.Forte@Sun.COM 
7807836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetDiscoveryAddressOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)7817836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDiscoveryAddressOidList(
7827836SJohn.Forte@Sun.COM 		IMA_OID Oid,
7837836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
7847836SJohn.Forte@Sun.COM )
7857836SJohn.Forte@Sun.COM {
7867836SJohn.Forte@Sun.COM 	int fd, i, addr_list_size;
7877836SJohn.Forte@Sun.COM 	iscsi_addr_list_t *idlp, al_info;
7887836SJohn.Forte@Sun.COM 
7897836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
7907836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
7917836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
7927836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
7937836SJohn.Forte@Sun.COM 	}
7947836SJohn.Forte@Sun.COM 
7957836SJohn.Forte@Sun.COM 	(void) memset(&al_info, 0, sizeof (al_info));
7967836SJohn.Forte@Sun.COM 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
7977836SJohn.Forte@Sun.COM 	al_info.al_in_cnt = 0;
7987836SJohn.Forte@Sun.COM 
7997836SJohn.Forte@Sun.COM 	/*
8007836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the number of targets.
8017836SJohn.Forte@Sun.COM 	 */
8027836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
8037836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
8047836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
8057836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
8067836SJohn.Forte@Sun.COM 		(void) close(fd);
8077836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
8087836SJohn.Forte@Sun.COM 	}
8097836SJohn.Forte@Sun.COM 
8107836SJohn.Forte@Sun.COM 	addr_list_size = sizeof (iscsi_addr_list_t);
8117836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt > 1) {
8127836SJohn.Forte@Sun.COM 		addr_list_size += (sizeof (iscsi_addr_list_t) *
8137836SJohn.Forte@Sun.COM 		    al_info.al_out_cnt - 1);
8147836SJohn.Forte@Sun.COM 	}
8157836SJohn.Forte@Sun.COM 
8167836SJohn.Forte@Sun.COM 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
8177836SJohn.Forte@Sun.COM 	if (idlp == NULL) {
8187836SJohn.Forte@Sun.COM 		(void) close(fd);
8197836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
8207836SJohn.Forte@Sun.COM 	}
8217836SJohn.Forte@Sun.COM 
8227836SJohn.Forte@Sun.COM 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
8237836SJohn.Forte@Sun.COM 	idlp->al_in_cnt = al_info.al_out_cnt;
8247836SJohn.Forte@Sun.COM 	/* Issue the same ioctl again to obtain the OIDs. */
8257836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
8267836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
8277836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
8287836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
8297836SJohn.Forte@Sun.COM 		free(idlp);
8307836SJohn.Forte@Sun.COM 		(void) close(fd);
8317836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
8327836SJohn.Forte@Sun.COM 	}
8337836SJohn.Forte@Sun.COM 
8347836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) +
8357836SJohn.Forte@Sun.COM 	    idlp->al_out_cnt * sizeof (IMA_OID));
8367836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
8377836SJohn.Forte@Sun.COM 		free(idlp);
8387836SJohn.Forte@Sun.COM 		(void) close(fd);
8397836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
8407836SJohn.Forte@Sun.COM 	}
8417836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = idlp->al_out_cnt;
8427836SJohn.Forte@Sun.COM 
8437836SJohn.Forte@Sun.COM 	for (i = 0; i < idlp->al_out_cnt; i++) {
8447836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].objectType =
8457836SJohn.Forte@Sun.COM 		    IMA_OBJECT_TYPE_DISCOVERY_ADDRESS;
8467836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].ownerId = pluginOwnerId;
8477836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].objectSequenceNumber =
8487836SJohn.Forte@Sun.COM 		    idlp->al_addrs[i].a_oid;
8497836SJohn.Forte@Sun.COM 	}
8507836SJohn.Forte@Sun.COM 
8517836SJohn.Forte@Sun.COM 	free(idlp);
8527836SJohn.Forte@Sun.COM 	(void) close(fd);
8537836SJohn.Forte@Sun.COM 
8547836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
8557836SJohn.Forte@Sun.COM }
8567836SJohn.Forte@Sun.COM 
8577836SJohn.Forte@Sun.COM 
8587836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetStaticDiscoveryTargetOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)8597836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetStaticDiscoveryTargetOidList(
8607836SJohn.Forte@Sun.COM 		IMA_OID Oid,
8617836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
8627836SJohn.Forte@Sun.COM )
8637836SJohn.Forte@Sun.COM {
8647836SJohn.Forte@Sun.COM 	if (Oid.objectType == IMA_OBJECT_TYPE_PNP) {
8657836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
8667836SJohn.Forte@Sun.COM 	}
8677836SJohn.Forte@Sun.COM 
8687836SJohn.Forte@Sun.COM 	return (get_target_oid_list(ISCSI_STATIC_TGT_OID_LIST, ppList));
8697836SJohn.Forte@Sun.COM }
8707836SJohn.Forte@Sun.COM 
8717836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetTargetOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)8727836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetTargetOidList(
8737836SJohn.Forte@Sun.COM 		IMA_OID Oid,
8747836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
8757836SJohn.Forte@Sun.COM )
8767836SJohn.Forte@Sun.COM {
8777836SJohn.Forte@Sun.COM 	return (get_target_oid_list(ISCSI_TGT_PARAM_OID_LIST, ppList));
8787836SJohn.Forte@Sun.COM }
8797836SJohn.Forte@Sun.COM 
8807836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_SetIsnsDiscovery(IMA_OID phbaId,IMA_BOOL enableIsnsDiscovery,IMA_ISNS_DISCOVERY_METHOD discoveryMethod,const IMA_HOST_ID * iSnsHost)8817836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetIsnsDiscovery(
8827836SJohn.Forte@Sun.COM 		IMA_OID phbaId,
8837836SJohn.Forte@Sun.COM 		IMA_BOOL enableIsnsDiscovery,
8847836SJohn.Forte@Sun.COM 		IMA_ISNS_DISCOVERY_METHOD discoveryMethod,
8857836SJohn.Forte@Sun.COM 		const IMA_HOST_ID *iSnsHost
8867836SJohn.Forte@Sun.COM )
8877836SJohn.Forte@Sun.COM {
8887836SJohn.Forte@Sun.COM 	/* XXX need to set discovery Method and domaineName */
8897836SJohn.Forte@Sun.COM 	return (configure_discovery_method(enableIsnsDiscovery,
8907836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodISNS));
8917836SJohn.Forte@Sun.COM }
8927836SJohn.Forte@Sun.COM 
8937836SJohn.Forte@Sun.COM 
8947836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetSlpDiscovery(IMA_OID phbaId,IMA_BOOL enableSlpDiscovery)8957836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetSlpDiscovery(
8967836SJohn.Forte@Sun.COM 		IMA_OID phbaId,
8977836SJohn.Forte@Sun.COM 		IMA_BOOL enableSlpDiscovery
8987836SJohn.Forte@Sun.COM )
8997836SJohn.Forte@Sun.COM {
9007836SJohn.Forte@Sun.COM 	return (configure_discovery_method(enableSlpDiscovery,
9017836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodSLP));
9027836SJohn.Forte@Sun.COM }
9037836SJohn.Forte@Sun.COM 
9047836SJohn.Forte@Sun.COM 
9057836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetStaticDiscovery(IMA_OID phbaId,IMA_BOOL enableStaticDiscovery)9067836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetStaticDiscovery(
9077836SJohn.Forte@Sun.COM 		IMA_OID phbaId,
9087836SJohn.Forte@Sun.COM 		IMA_BOOL enableStaticDiscovery
9097836SJohn.Forte@Sun.COM )
9107836SJohn.Forte@Sun.COM {
9117836SJohn.Forte@Sun.COM 	return (configure_discovery_method(enableStaticDiscovery,
9127836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodStatic));
9137836SJohn.Forte@Sun.COM }
9147836SJohn.Forte@Sun.COM 
9157836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetSendTargetsDiscovery(IMA_OID phbaId,IMA_BOOL enableSendTargetsDiscovery)9167836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetSendTargetsDiscovery(
9177836SJohn.Forte@Sun.COM 		IMA_OID phbaId,
9187836SJohn.Forte@Sun.COM 		IMA_BOOL enableSendTargetsDiscovery
9197836SJohn.Forte@Sun.COM )
9207836SJohn.Forte@Sun.COM {
9217836SJohn.Forte@Sun.COM 	return (configure_discovery_method(enableSendTargetsDiscovery,
9227836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodSendTargets));
9237836SJohn.Forte@Sun.COM }
9247836SJohn.Forte@Sun.COM 
9257836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_RemoveDiscoveryAddress(IMA_OID discoveryAddressOid)9267836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveDiscoveryAddress(
9277836SJohn.Forte@Sun.COM 		IMA_OID	discoveryAddressOid
9287836SJohn.Forte@Sun.COM )
9297836SJohn.Forte@Sun.COM {
9307836SJohn.Forte@Sun.COM 	int status, fd, i, addr_list_size;
9317836SJohn.Forte@Sun.COM 	iscsi_addr_list_t *idlp, al_info;
9327836SJohn.Forte@Sun.COM 	iscsi_addr_t *matched_addr = NULL;
9337836SJohn.Forte@Sun.COM 	entry_t	entry;
9347836SJohn.Forte@Sun.COM 
9357836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
9367836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
9377836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
9387836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
9397836SJohn.Forte@Sun.COM 	}
9407836SJohn.Forte@Sun.COM 
9417836SJohn.Forte@Sun.COM 	(void) memset(&al_info, 0, sizeof (al_info));
9427836SJohn.Forte@Sun.COM 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
9437836SJohn.Forte@Sun.COM 	al_info.al_in_cnt = 0;
9447836SJohn.Forte@Sun.COM 
9457836SJohn.Forte@Sun.COM 	/*
9467836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the number of discovery address.
9477836SJohn.Forte@Sun.COM 	 */
9487836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
9497836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
9507836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
9517836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
9527836SJohn.Forte@Sun.COM 		(void) close(fd);
9537836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
9547836SJohn.Forte@Sun.COM 	}
9557836SJohn.Forte@Sun.COM 
9567836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt == 0) {
9577836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
9587836SJohn.Forte@Sun.COM 	}
9597836SJohn.Forte@Sun.COM 
9607836SJohn.Forte@Sun.COM 	addr_list_size = sizeof (iscsi_addr_list_t);
9617836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt > 1) {
9627836SJohn.Forte@Sun.COM 		addr_list_size += (sizeof (iscsi_addr_list_t) *
9637836SJohn.Forte@Sun.COM 		    al_info.al_out_cnt - 1);
9647836SJohn.Forte@Sun.COM 	}
9657836SJohn.Forte@Sun.COM 
9667836SJohn.Forte@Sun.COM 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
9677836SJohn.Forte@Sun.COM 	if (idlp == NULL) {
9687836SJohn.Forte@Sun.COM 		(void) close(fd);
9697836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
9707836SJohn.Forte@Sun.COM 	}
9717836SJohn.Forte@Sun.COM 
9727836SJohn.Forte@Sun.COM 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
9737836SJohn.Forte@Sun.COM 	idlp->al_in_cnt = al_info.al_out_cnt;
9747836SJohn.Forte@Sun.COM 
9757836SJohn.Forte@Sun.COM 	/* Issue the same ioctl again to obtain the OIDs. */
9767836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
9777836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
9787836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
9797836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
9807836SJohn.Forte@Sun.COM 		free(idlp);
9817836SJohn.Forte@Sun.COM 		(void) close(fd);
9827836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
9837836SJohn.Forte@Sun.COM 	}
9847836SJohn.Forte@Sun.COM 
9857836SJohn.Forte@Sun.COM 	for (i = 0; i < idlp->al_out_cnt; i++) {
9867836SJohn.Forte@Sun.COM 		if (discoveryAddressOid.objectSequenceNumber !=
9877836SJohn.Forte@Sun.COM 		    idlp->al_addrs[i].a_oid)
9887836SJohn.Forte@Sun.COM 			continue;
9897836SJohn.Forte@Sun.COM 		matched_addr = &(idlp->al_addrs[i]);
9907836SJohn.Forte@Sun.COM 	}
9917836SJohn.Forte@Sun.COM 
9927836SJohn.Forte@Sun.COM 	if (matched_addr == NULL) {
9937836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
9947836SJohn.Forte@Sun.COM 	}
9957836SJohn.Forte@Sun.COM 
9967836SJohn.Forte@Sun.COM 
9977836SJohn.Forte@Sun.COM 	(void) memset(&entry, 0, sizeof (entry_t));
9987836SJohn.Forte@Sun.COM 	entry.e_vers = ISCSI_INTERFACE_VERSION;
9997836SJohn.Forte@Sun.COM 	entry.e_oid  = discoveryAddressOid.objectSequenceNumber;
10007836SJohn.Forte@Sun.COM 	if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) {
10017836SJohn.Forte@Sun.COM 		bcopy(&matched_addr->a_addr.i_addr.in4,
10027836SJohn.Forte@Sun.COM 		    &entry.e_u.u_in4, sizeof (entry.e_u.u_in4));
10037836SJohn.Forte@Sun.COM 		entry.e_insize = sizeof (struct in_addr);
10047836SJohn.Forte@Sun.COM 	} else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) {
10057836SJohn.Forte@Sun.COM 		bcopy(&matched_addr->a_addr.i_addr.in6,
10067836SJohn.Forte@Sun.COM 		    &entry.e_u.u_in6, sizeof (entry.e_u.u_in6));
10077836SJohn.Forte@Sun.COM 		entry.e_insize = sizeof (struct in6_addr);
10087836SJohn.Forte@Sun.COM 	} else {
10097836SJohn.Forte@Sun.COM 		/* Should not happen */
10107836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
10117836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET returned bad address");
10127836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
10137836SJohn.Forte@Sun.COM 	}
10147836SJohn.Forte@Sun.COM 
10157836SJohn.Forte@Sun.COM 	entry.e_port = matched_addr->a_port;
10167836SJohn.Forte@Sun.COM 	entry.e_tpgt = 0;
10177836SJohn.Forte@Sun.COM 	entry.e_oid = discoveryAddressOid.objectSequenceNumber;
10187836SJohn.Forte@Sun.COM 
10197836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_CLEAR, &entry)) {
10207836SJohn.Forte@Sun.COM 		status = errno;
10217836SJohn.Forte@Sun.COM 		(void) close(fd);
10227836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
10237836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_CLEAR ioctl failed, errno: %d",
10247836SJohn.Forte@Sun.COM 		    errno);
10257836SJohn.Forte@Sun.COM 		if (status == EBUSY) {
10267836SJohn.Forte@Sun.COM 			return (IMA_ERROR_LU_IN_USE);
10277836SJohn.Forte@Sun.COM 		} else {
10287836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
10297836SJohn.Forte@Sun.COM 		}
10307836SJohn.Forte@Sun.COM 	}
10317836SJohn.Forte@Sun.COM 
10327836SJohn.Forte@Sun.COM 	free(idlp);
10337836SJohn.Forte@Sun.COM 	(void) close(fd);
10347836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
10357836SJohn.Forte@Sun.COM }
10367836SJohn.Forte@Sun.COM 
10377836SJohn.Forte@Sun.COM 
10387836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_AddDiscoveryAddress(IMA_OID oid,const IMA_TARGET_ADDRESS discoveryAddress,IMA_OID * pDiscoveryAddressOid)10397836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_AddDiscoveryAddress(
10407836SJohn.Forte@Sun.COM 		IMA_OID	oid,
10417836SJohn.Forte@Sun.COM 		const IMA_TARGET_ADDRESS discoveryAddress,
10427836SJohn.Forte@Sun.COM 		IMA_OID	*pDiscoveryAddressOid
10437836SJohn.Forte@Sun.COM )
10447836SJohn.Forte@Sun.COM {
10457836SJohn.Forte@Sun.COM 	entry_t	    entry;
10467836SJohn.Forte@Sun.COM 	int	    fd;
10477836SJohn.Forte@Sun.COM 
10487836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
10497836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
10507836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
10517836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
10527836SJohn.Forte@Sun.COM 	}
10537836SJohn.Forte@Sun.COM 
10547836SJohn.Forte@Sun.COM 	if (prepare_discovery_entry(discoveryAddress, &entry) !=
10557836SJohn.Forte@Sun.COM 	    DISC_ADDR_OK) {
10567836SJohn.Forte@Sun.COM 		(void) close(fd);
10577836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
10587836SJohn.Forte@Sun.COM 	}
10597836SJohn.Forte@Sun.COM 
10607836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_SET, &entry)) {
10617836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
10627836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_SET ioctl failed, errno: %d",
10637836SJohn.Forte@Sun.COM 		    errno);
10647836SJohn.Forte@Sun.COM 		(void) close(fd);
10657836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
10667836SJohn.Forte@Sun.COM 	}
10677836SJohn.Forte@Sun.COM 
10687836SJohn.Forte@Sun.COM 	pDiscoveryAddressOid->ownerId = pluginOwnerId;
10697836SJohn.Forte@Sun.COM 	pDiscoveryAddressOid->objectType = IMA_OBJECT_TYPE_DISCOVERY_ADDRESS;
10707836SJohn.Forte@Sun.COM 	pDiscoveryAddressOid->objectSequenceNumber = entry.e_oid;
10717836SJohn.Forte@Sun.COM 
10727836SJohn.Forte@Sun.COM 	(void) close(fd);
10737836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
10747836SJohn.Forte@Sun.COM }
10757836SJohn.Forte@Sun.COM 
IMA_GetStaticDiscoveryTargetProperties(IMA_OID staticTargetOid,IMA_STATIC_DISCOVERY_TARGET_PROPERTIES * pProps)10767836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetStaticDiscoveryTargetProperties(
10777836SJohn.Forte@Sun.COM 		IMA_OID	staticTargetOid,
10787836SJohn.Forte@Sun.COM 		IMA_STATIC_DISCOVERY_TARGET_PROPERTIES *pProps
10797836SJohn.Forte@Sun.COM )
10807836SJohn.Forte@Sun.COM {
10817836SJohn.Forte@Sun.COM 	char static_target_addr_str[SUN_IMA_IP_ADDRESS_LEN];
10827836SJohn.Forte@Sun.COM 	char static_target_addr_port_str[SUN_IMA_IP_ADDRESS_LEN];
10837836SJohn.Forte@Sun.COM 	int af, fd, status;
10847836SJohn.Forte@Sun.COM 	iscsi_static_property_t prop;
10857836SJohn.Forte@Sun.COM 	/* LINTED */
10867836SJohn.Forte@Sun.COM 	IMA_HOST_ID *host;
10877836SJohn.Forte@Sun.COM 
10887836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
10897836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
10907836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
10917836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
10927836SJohn.Forte@Sun.COM 	}
10937836SJohn.Forte@Sun.COM 
10947836SJohn.Forte@Sun.COM 	(void) memset(&prop, 0, sizeof (iscsi_static_property_t));
10957836SJohn.Forte@Sun.COM 	prop.p_vers = ISCSI_INTERFACE_VERSION;
10967836SJohn.Forte@Sun.COM 	prop.p_oid = (uint32_t)staticTargetOid.objectSequenceNumber;
10977836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_STATIC_GET, &prop) != 0) {
10987836SJohn.Forte@Sun.COM 		status = errno;
10997836SJohn.Forte@Sun.COM 		(void) close(fd);
11007836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
11017836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET ioctl failed, errno: %d", status);
11027836SJohn.Forte@Sun.COM 		if (status == ENOENT) {
11037836SJohn.Forte@Sun.COM 			return (IMA_ERROR_OBJECT_NOT_FOUND);
11047836SJohn.Forte@Sun.COM 
11057836SJohn.Forte@Sun.COM 		} else {
11067836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
11077836SJohn.Forte@Sun.COM 		}
11087836SJohn.Forte@Sun.COM 	}
11097836SJohn.Forte@Sun.COM 	(void) close(fd);
11107836SJohn.Forte@Sun.COM 
11117836SJohn.Forte@Sun.COM 	(void) mbstowcs(pProps->staticTarget.targetName, (char *)prop.p_name,
11127836SJohn.Forte@Sun.COM 	    sizeof (pProps->staticTarget.targetName)/sizeof (IMA_WCHAR));
11137836SJohn.Forte@Sun.COM 
11147836SJohn.Forte@Sun.COM 	if (prop.p_addr_list.al_addrs[0].a_addr.i_insize ==
11157836SJohn.Forte@Sun.COM 	    sizeof (struct in_addr)) {
11167836SJohn.Forte@Sun.COM 		/* IPv4 */
11177836SJohn.Forte@Sun.COM 		af = AF_INET;
11187836SJohn.Forte@Sun.COM 	} else if (prop.p_addr_list.al_addrs[0].a_addr.i_insize ==
11197836SJohn.Forte@Sun.COM 	    sizeof (struct in6_addr)) {
11207836SJohn.Forte@Sun.COM 		/* IPv6 */
11217836SJohn.Forte@Sun.COM 		af = AF_INET6;
11227836SJohn.Forte@Sun.COM 	} else {
11237836SJohn.Forte@Sun.COM 		/* Should not happen */
11247836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
11257836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET returned bad address");
11267836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
11277836SJohn.Forte@Sun.COM 	}
11287836SJohn.Forte@Sun.COM 
11297836SJohn.Forte@Sun.COM 	if (inet_ntop(af, &prop.p_addr_list.al_addrs[0].a_addr.i_addr,
11307836SJohn.Forte@Sun.COM 	    static_target_addr_str, sizeof (static_target_addr_str)) == NULL) {
11317836SJohn.Forte@Sun.COM 		/* Should not happen */
11327836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
11337836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET returned address that cannot "
11347836SJohn.Forte@Sun.COM 		    "be inet_ntop");
11357836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
11367836SJohn.Forte@Sun.COM 	} else {
11377836SJohn.Forte@Sun.COM 		if (af == AF_INET) {
11387836SJohn.Forte@Sun.COM 			(void) snprintf(static_target_addr_port_str,
11397836SJohn.Forte@Sun.COM 			    SUN_IMA_IP_ADDRESS_LEN,
11407836SJohn.Forte@Sun.COM 			    "%s:%ld",
11417836SJohn.Forte@Sun.COM 			    static_target_addr_str,
11427836SJohn.Forte@Sun.COM 			    prop.p_addr_list.al_addrs[0].a_port);
11437836SJohn.Forte@Sun.COM 		} else {
11447836SJohn.Forte@Sun.COM 			(void) snprintf(static_target_addr_port_str,
11457836SJohn.Forte@Sun.COM 			    SUN_IMA_IP_ADDRESS_LEN,
11467836SJohn.Forte@Sun.COM 			    "[%s]:%ld",
11477836SJohn.Forte@Sun.COM 			    static_target_addr_str,
11487836SJohn.Forte@Sun.COM 			    prop.p_addr_list.al_addrs[0].a_port);
11497836SJohn.Forte@Sun.COM 		}
11507836SJohn.Forte@Sun.COM 		host = &pProps->staticTarget.targetAddress.hostnameIpAddress;
11517836SJohn.Forte@Sun.COM 		(void) mbstowcs(pProps->staticTarget.
11527836SJohn.Forte@Sun.COM 		    targetAddress.hostnameIpAddress.
11537836SJohn.Forte@Sun.COM 		    id.hostname, static_target_addr_port_str,
11547836SJohn.Forte@Sun.COM 		    sizeof (host->id.hostname) / sizeof (IMA_WCHAR));
11557836SJohn.Forte@Sun.COM 	}
11567836SJohn.Forte@Sun.COM 
11577836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
11587836SJohn.Forte@Sun.COM }
11597836SJohn.Forte@Sun.COM 
11607836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetDiscoveryAddressProperties(IMA_OID discoveryAddressOid,IMA_DISCOVERY_ADDRESS_PROPERTIES * pProps)11617836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDiscoveryAddressProperties(
11627836SJohn.Forte@Sun.COM 		IMA_OID	discoveryAddressOid,
11637836SJohn.Forte@Sun.COM 		IMA_DISCOVERY_ADDRESS_PROPERTIES *pProps
11647836SJohn.Forte@Sun.COM )
11657836SJohn.Forte@Sun.COM {
11667836SJohn.Forte@Sun.COM 	int fd;
11677836SJohn.Forte@Sun.COM 	int i;
11687836SJohn.Forte@Sun.COM 	int addr_list_size;
11697836SJohn.Forte@Sun.COM 	iscsi_addr_list_t *idlp, al_info;
11707836SJohn.Forte@Sun.COM 	iscsi_addr_t *matched_addr = NULL;
11717836SJohn.Forte@Sun.COM 	/* LINTED */
11727836SJohn.Forte@Sun.COM 	IMA_TARGET_ADDRESS *addr;
11737836SJohn.Forte@Sun.COM 
11747836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
11757836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
11767836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
11777836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
11787836SJohn.Forte@Sun.COM 	}
11797836SJohn.Forte@Sun.COM 
11807836SJohn.Forte@Sun.COM 	(void) memset(&al_info, 0, sizeof (al_info));
11817836SJohn.Forte@Sun.COM 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
11827836SJohn.Forte@Sun.COM 	al_info.al_in_cnt = 0;
11837836SJohn.Forte@Sun.COM 
11847836SJohn.Forte@Sun.COM 	/*
11857836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the number of discovery addresses.
11867836SJohn.Forte@Sun.COM 	 */
11877836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
11887836SJohn.Forte@Sun.COM 		(void) close(fd);
11897836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
11907836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
11917836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
11927836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
11937836SJohn.Forte@Sun.COM 	}
11947836SJohn.Forte@Sun.COM 
11957836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt == 0) {
11967836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
11977836SJohn.Forte@Sun.COM 	}
11987836SJohn.Forte@Sun.COM 
11997836SJohn.Forte@Sun.COM 	addr_list_size = sizeof (iscsi_addr_list_t);
12007836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt > 1) {
12017836SJohn.Forte@Sun.COM 		addr_list_size += (sizeof (iscsi_addr_list_t) *
12027836SJohn.Forte@Sun.COM 		    al_info.al_out_cnt - 1);
12037836SJohn.Forte@Sun.COM 	}
12047836SJohn.Forte@Sun.COM 
12057836SJohn.Forte@Sun.COM 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
12067836SJohn.Forte@Sun.COM 	if (idlp == NULL) {
12077836SJohn.Forte@Sun.COM 		(void) close(fd);
12087836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
12097836SJohn.Forte@Sun.COM 	}
12107836SJohn.Forte@Sun.COM 
12117836SJohn.Forte@Sun.COM 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
12127836SJohn.Forte@Sun.COM 	idlp->al_in_cnt = al_info.al_out_cnt;
12137836SJohn.Forte@Sun.COM 
12147836SJohn.Forte@Sun.COM 	/* Issue the same ioctl again to obtain the OIDs. */
12157836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
12167836SJohn.Forte@Sun.COM 		free(idlp);
12177836SJohn.Forte@Sun.COM 		(void) close(fd);
12187836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
12197836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
12207836SJohn.Forte@Sun.COM 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
12217836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
12227836SJohn.Forte@Sun.COM 	}
12237836SJohn.Forte@Sun.COM 
12247836SJohn.Forte@Sun.COM 	for (i = 0; i < idlp->al_out_cnt; i++) {
12257836SJohn.Forte@Sun.COM 		if (discoveryAddressOid.objectSequenceNumber !=
12267836SJohn.Forte@Sun.COM 		    idlp->al_addrs[i].a_oid)
12277836SJohn.Forte@Sun.COM 			continue;
12287836SJohn.Forte@Sun.COM 		matched_addr = &(idlp->al_addrs[i]);
12297836SJohn.Forte@Sun.COM 	}
12307836SJohn.Forte@Sun.COM 
12317836SJohn.Forte@Sun.COM 	if (matched_addr == NULL) {
12327836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
12337836SJohn.Forte@Sun.COM 	}
12347836SJohn.Forte@Sun.COM 
12357836SJohn.Forte@Sun.COM 	if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) {
12367836SJohn.Forte@Sun.COM 		pProps->discoveryAddress.hostnameIpAddress.id.
12377836SJohn.Forte@Sun.COM 		    ipAddress.ipv4Address = IMA_TRUE;
12387836SJohn.Forte@Sun.COM 	} else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) {
12397836SJohn.Forte@Sun.COM 		pProps->discoveryAddress.hostnameIpAddress.id.
12407836SJohn.Forte@Sun.COM 		    ipAddress.ipv4Address = IMA_FALSE;
12417836SJohn.Forte@Sun.COM 	} else {
12427836SJohn.Forte@Sun.COM 		/* Should not happen */
12437836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
12447836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET returned bad address");
12457836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
12467836SJohn.Forte@Sun.COM 	}
12477836SJohn.Forte@Sun.COM 
12487836SJohn.Forte@Sun.COM 	addr = &pProps->discoveryAddress;
12497836SJohn.Forte@Sun.COM 	bcopy(&(matched_addr->a_addr.i_addr), pProps->discoveryAddress.
12507836SJohn.Forte@Sun.COM 	    hostnameIpAddress.id.ipAddress.ipAddress,
12517836SJohn.Forte@Sun.COM 	    sizeof (addr->hostnameIpAddress.id.ipAddress.ipAddress));
12527836SJohn.Forte@Sun.COM 
12537836SJohn.Forte@Sun.COM 	pProps->discoveryAddress.portNumber = matched_addr->a_port;
12547836SJohn.Forte@Sun.COM 
12557836SJohn.Forte@Sun.COM 	pProps->associatedLhbaOid.objectType = IMA_OBJECT_TYPE_LHBA;
12567836SJohn.Forte@Sun.COM 	pProps->associatedLhbaOid.ownerId = pluginOwnerId;
12577836SJohn.Forte@Sun.COM 	pProps->associatedLhbaOid.objectSequenceNumber = ISCSI_INITIATOR_OID;
12587836SJohn.Forte@Sun.COM 
12597836SJohn.Forte@Sun.COM 	free(idlp);
12607836SJohn.Forte@Sun.COM 	(void) close(fd);
12617836SJohn.Forte@Sun.COM 
12627836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
12637836SJohn.Forte@Sun.COM }
12647836SJohn.Forte@Sun.COM 
IMA_RemoveStaticDiscoveryTarget(IMA_OID staticTargetOid)12657836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveStaticDiscoveryTarget(
12667836SJohn.Forte@Sun.COM 		IMA_OID staticTargetOid
12677836SJohn.Forte@Sun.COM )
12687836SJohn.Forte@Sun.COM {
12697836SJohn.Forte@Sun.COM 	entry_t	entry;
12707836SJohn.Forte@Sun.COM 	int	status, fd;
12717836SJohn.Forte@Sun.COM 
12727836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
12737836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
12747836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
12757836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
12767836SJohn.Forte@Sun.COM 	}
12777836SJohn.Forte@Sun.COM 
12787836SJohn.Forte@Sun.COM 	(void) memset(&entry, 0, sizeof (entry_t));
12797836SJohn.Forte@Sun.COM 	entry.e_vers = ISCSI_INTERFACE_VERSION;
12807836SJohn.Forte@Sun.COM 	entry.e_oid = (uint32_t)staticTargetOid.objectSequenceNumber;
12817836SJohn.Forte@Sun.COM 
12827836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_STATIC_CLEAR, &entry)) {
12837836SJohn.Forte@Sun.COM 		status = errno;
12847836SJohn.Forte@Sun.COM 		(void) close(fd);
12857836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
12867836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_CLEAR ioctl failed, errno: %d", errno);
12877836SJohn.Forte@Sun.COM 		if (status == EBUSY) {
12887836SJohn.Forte@Sun.COM 			return (IMA_ERROR_LU_IN_USE);
12897836SJohn.Forte@Sun.COM 		} else {
12907836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
12917836SJohn.Forte@Sun.COM 		}
12927836SJohn.Forte@Sun.COM 	}
12937836SJohn.Forte@Sun.COM 
12947836SJohn.Forte@Sun.COM 	(void) close(fd);
12957836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
12967836SJohn.Forte@Sun.COM }
12977836SJohn.Forte@Sun.COM 
12987836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_AddStaticDiscoveryTarget(IMA_OID lhbaOid,const IMA_STATIC_DISCOVERY_TARGET staticConfig,IMA_OID * pTargetOid)12997836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_AddStaticDiscoveryTarget(
13007836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
13017836SJohn.Forte@Sun.COM 		const IMA_STATIC_DISCOVERY_TARGET staticConfig,
13027836SJohn.Forte@Sun.COM 		IMA_OID *pTargetOid
13037836SJohn.Forte@Sun.COM )
13047836SJohn.Forte@Sun.COM {
13057836SJohn.Forte@Sun.COM 	char			tmp_target_str[SUN_IMA_IP_ADDRESS_LEN];
13067836SJohn.Forte@Sun.COM 	char			target_addr_str[SUN_IMA_IP_ADDRESS_LEN];
13077836SJohn.Forte@Sun.COM 	char			target_port_str[SUN_IMA_IP_PORT_LEN];
13087836SJohn.Forte@Sun.COM 	iscsi_target_entry_t	target;
13097836SJohn.Forte@Sun.COM 	int			fd;
13107836SJohn.Forte@Sun.COM 	int			target_in_addr_size;
13117836SJohn.Forte@Sun.COM 	int			target_port;
13127836SJohn.Forte@Sun.COM 	union {
13137836SJohn.Forte@Sun.COM 		struct in_addr	u_in4;
13147836SJohn.Forte@Sun.COM 		struct in6_addr	u_in6;
13157836SJohn.Forte@Sun.COM 	}			target_in;
13167836SJohn.Forte@Sun.COM 
13177836SJohn.Forte@Sun.COM 	/*
13187836SJohn.Forte@Sun.COM 	 * staticConfig.address may come in with port number at its trailer.
13197836SJohn.Forte@Sun.COM 	 * Parse it to separate the IP address and port number.
13207836SJohn.Forte@Sun.COM 	 * Also translate the hostname to IP address if needed.
13217836SJohn.Forte@Sun.COM 	 */
13227836SJohn.Forte@Sun.COM 	(void) wcstombs(tmp_target_str,
13237836SJohn.Forte@Sun.COM 	    staticConfig.targetAddress.hostnameIpAddress.
13247836SJohn.Forte@Sun.COM 	    id.hostname, sizeof (tmp_target_str));
13257836SJohn.Forte@Sun.COM 
13267836SJohn.Forte@Sun.COM 	if (tmp_target_str[0] == '[') {
13277836SJohn.Forte@Sun.COM 		/* IPv6 address */
13287836SJohn.Forte@Sun.COM 		char *closeBracketPos;
13297836SJohn.Forte@Sun.COM 		closeBracketPos = strchr(tmp_target_str, ']');
13307836SJohn.Forte@Sun.COM 		if (!closeBracketPos) {
13317836SJohn.Forte@Sun.COM 			return (IMA_ERROR_INVALID_PARAMETER);
13327836SJohn.Forte@Sun.COM 		}
13337836SJohn.Forte@Sun.COM 
13347836SJohn.Forte@Sun.COM 		*closeBracketPos = NULL;
13357836SJohn.Forte@Sun.COM 		(void) strlcpy(target_addr_str, &tmp_target_str[1],
13367836SJohn.Forte@Sun.COM 		    sizeof (target_addr_str));
13377836SJohn.Forte@Sun.COM 
13387836SJohn.Forte@Sun.COM 		if (inet_pton(AF_INET6, target_addr_str,
13397836SJohn.Forte@Sun.COM 		    &target_in.u_in6) != 1) {
13407836SJohn.Forte@Sun.COM 			return (IMA_ERROR_INVALID_PARAMETER);
13417836SJohn.Forte@Sun.COM 		}
13427836SJohn.Forte@Sun.COM 		target_in_addr_size = sizeof (struct in6_addr);
13437836SJohn.Forte@Sun.COM 
13447836SJohn.Forte@Sun.COM 		/* Extract the port number */
13457836SJohn.Forte@Sun.COM 		closeBracketPos++;
13467836SJohn.Forte@Sun.COM 		if (*closeBracketPos == ':') {
13477836SJohn.Forte@Sun.COM 			closeBracketPos++;
13487836SJohn.Forte@Sun.COM 
13497836SJohn.Forte@Sun.COM 			if (*closeBracketPos != NULL) {
13507836SJohn.Forte@Sun.COM 				(void) strlcpy(target_port_str, closeBracketPos,
13517836SJohn.Forte@Sun.COM 				    sizeof (target_port_str));
13527836SJohn.Forte@Sun.COM 				target_port = atoi(target_port_str);
13537836SJohn.Forte@Sun.COM 			} else {
13547836SJohn.Forte@Sun.COM 				target_port = ISCSI_LISTEN_PORT;
13557836SJohn.Forte@Sun.COM 			}
13567836SJohn.Forte@Sun.COM 		} else {
13577836SJohn.Forte@Sun.COM 			/* No port number specified; use default port */
13587836SJohn.Forte@Sun.COM 			target_port = ISCSI_LISTEN_PORT;
13597836SJohn.Forte@Sun.COM 		}
13607836SJohn.Forte@Sun.COM 	} else {
13617836SJohn.Forte@Sun.COM 		/* IPv4 address */
13627836SJohn.Forte@Sun.COM 		char *colonPos;
13637836SJohn.Forte@Sun.COM 		colonPos = strchr(tmp_target_str, ':');
13647836SJohn.Forte@Sun.COM 		if (!colonPos) {
13657836SJohn.Forte@Sun.COM 			/* No port number specified; use default port */
13667836SJohn.Forte@Sun.COM 			target_port = ISCSI_LISTEN_PORT;
13677836SJohn.Forte@Sun.COM 			(void) strlcpy(target_addr_str, tmp_target_str,
13687836SJohn.Forte@Sun.COM 			    sizeof (target_addr_str));
13697836SJohn.Forte@Sun.COM 		} else {
13707836SJohn.Forte@Sun.COM 			*colonPos = NULL;
13717836SJohn.Forte@Sun.COM 			(void) strlcpy(target_addr_str, tmp_target_str,
13727836SJohn.Forte@Sun.COM 			    sizeof (target_addr_str));
13737836SJohn.Forte@Sun.COM 			/* Extract the port number */
13747836SJohn.Forte@Sun.COM 			colonPos++;
13757836SJohn.Forte@Sun.COM 			if (*colonPos != NULL) {
13767836SJohn.Forte@Sun.COM 				(void) strlcpy(target_port_str, colonPos,
13777836SJohn.Forte@Sun.COM 				    sizeof (target_port_str));
13787836SJohn.Forte@Sun.COM 				target_port = atoi(target_port_str);
13797836SJohn.Forte@Sun.COM 			} else {
13807836SJohn.Forte@Sun.COM 				target_port = ISCSI_LISTEN_PORT;
13817836SJohn.Forte@Sun.COM 			}
13827836SJohn.Forte@Sun.COM 		}
13837836SJohn.Forte@Sun.COM 
13847836SJohn.Forte@Sun.COM 		if (inet_pton(AF_INET, target_addr_str,
13857836SJohn.Forte@Sun.COM 		    &target_in.u_in4) != 1) {
13867836SJohn.Forte@Sun.COM 			return (IMA_ERROR_INVALID_PARAMETER);
13877836SJohn.Forte@Sun.COM 		}
13887836SJohn.Forte@Sun.COM 
13897836SJohn.Forte@Sun.COM 		target_in_addr_size = sizeof (struct in_addr);
13907836SJohn.Forte@Sun.COM 	}
13917836SJohn.Forte@Sun.COM 
13927836SJohn.Forte@Sun.COM 
13937836SJohn.Forte@Sun.COM 	(void) memset(&target, 0, sizeof (iscsi_target_entry_t));
13947836SJohn.Forte@Sun.COM 	target.te_entry.e_vers = ISCSI_INTERFACE_VERSION;
13957836SJohn.Forte@Sun.COM 	target.te_entry.e_oid = ISCSI_OID_NOTSET;
13967836SJohn.Forte@Sun.COM 	target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT;
13977836SJohn.Forte@Sun.COM 
13987836SJohn.Forte@Sun.COM 	(void) wcstombs((char *)target.te_name, staticConfig.targetName,
13997836SJohn.Forte@Sun.COM 	    ISCSI_MAX_NAME_LEN);
14007836SJohn.Forte@Sun.COM 
14017836SJohn.Forte@Sun.COM 	target.te_entry.e_insize = target_in_addr_size;
14027836SJohn.Forte@Sun.COM 	if (target.te_entry.e_insize == sizeof (struct in_addr)) {
14037836SJohn.Forte@Sun.COM 		target.te_entry.e_u.u_in4.s_addr = target_in.u_in4.s_addr;
14047836SJohn.Forte@Sun.COM 	} else if (target.te_entry.e_insize == sizeof (struct in6_addr)) {
14057836SJohn.Forte@Sun.COM 		bcopy(target_in.u_in6.s6_addr,
14067836SJohn.Forte@Sun.COM 		    target.te_entry.e_u.u_in6.s6_addr,
14077836SJohn.Forte@Sun.COM 		    sizeof (struct in6_addr));
14087836SJohn.Forte@Sun.COM 	} else {
14097836SJohn.Forte@Sun.COM 		/* Should not happen */
14107836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
14117836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_GET returned bad address");
14127836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
14137836SJohn.Forte@Sun.COM 	}
14147836SJohn.Forte@Sun.COM 
14157836SJohn.Forte@Sun.COM 	target.te_entry.e_port = target_port;
14167836SJohn.Forte@Sun.COM 
14177836SJohn.Forte@Sun.COM 	/* No target portal group specified. Default to -1. */
14187836SJohn.Forte@Sun.COM 	target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT;
14197836SJohn.Forte@Sun.COM 
14207836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
14217836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
14227836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
14237836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
14247836SJohn.Forte@Sun.COM 	}
14257836SJohn.Forte@Sun.COM 
14267836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_STATIC_SET, &target)) {
14277836SJohn.Forte@Sun.COM 		/*
14287836SJohn.Forte@Sun.COM 		 * Encountered problem setting the IP address and port for
14297836SJohn.Forte@Sun.COM 		 * the target just added.
14307836SJohn.Forte@Sun.COM 		 */
14317836SJohn.Forte@Sun.COM 		(void) close(fd);
14327836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
14337836SJohn.Forte@Sun.COM 		    "ISCSI_STATIC_SET ioctl failed, errno: %d", errno);
14347836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
14357836SJohn.Forte@Sun.COM 	}
14367836SJohn.Forte@Sun.COM 
14377836SJohn.Forte@Sun.COM 	pTargetOid->objectType = IMA_OBJECT_TYPE_TARGET;
14387836SJohn.Forte@Sun.COM 	pTargetOid->ownerId = pluginOwnerId;
14397836SJohn.Forte@Sun.COM 	pTargetOid->objectSequenceNumber = target.te_entry.e_oid;
14407836SJohn.Forte@Sun.COM 
14417836SJohn.Forte@Sun.COM 	(void) close(fd);
14427836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
14437836SJohn.Forte@Sun.COM }
14447836SJohn.Forte@Sun.COM 
IMA_GetTargetProperties(IMA_OID targetId,IMA_TARGET_PROPERTIES * pProps)14457836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetTargetProperties(
14467836SJohn.Forte@Sun.COM 		IMA_OID targetId,
14477836SJohn.Forte@Sun.COM 		IMA_TARGET_PROPERTIES *pProps
14487836SJohn.Forte@Sun.COM )
14497836SJohn.Forte@Sun.COM {
14507836SJohn.Forte@Sun.COM 	return (getTargetProperties(targetId, pProps));
14517836SJohn.Forte@Sun.COM }
14527836SJohn.Forte@Sun.COM 
getTargetProperties(IMA_OID targetId,IMA_TARGET_PROPERTIES * pProps)14537836SJohn.Forte@Sun.COM static IMA_STATUS getTargetProperties(
14547836SJohn.Forte@Sun.COM 		IMA_OID targetId,
14557836SJohn.Forte@Sun.COM 		IMA_TARGET_PROPERTIES *pProps
14567836SJohn.Forte@Sun.COM )
14577836SJohn.Forte@Sun.COM {
14587836SJohn.Forte@Sun.COM 	int		    fd;
14597836SJohn.Forte@Sun.COM 	iscsi_property_t    prop;
14607836SJohn.Forte@Sun.COM 
14617836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
14627836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
14637836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
14647836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
14657836SJohn.Forte@Sun.COM 	}
14667836SJohn.Forte@Sun.COM 
14677836SJohn.Forte@Sun.COM 	(void) memset(&prop, 0, sizeof (iscsi_property_t));
14687836SJohn.Forte@Sun.COM 	prop.p_vers = ISCSI_INTERFACE_VERSION;
14697836SJohn.Forte@Sun.COM 	prop.p_oid = (uint32_t)targetId.objectSequenceNumber;
14707836SJohn.Forte@Sun.COM 
14717836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_TARGET_PROPS_GET, &prop) != 0) {
14727836SJohn.Forte@Sun.COM 		(void) close(fd);
14737836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
14747836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
14757836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
14767836SJohn.Forte@Sun.COM 	}
14777836SJohn.Forte@Sun.COM 
14787836SJohn.Forte@Sun.COM 	(void) mbstowcs(pProps->name, (char *)prop.p_name, IMA_NODE_NAME_LEN);
14797836SJohn.Forte@Sun.COM 	(void) memset(pProps->alias, 0,
14807836SJohn.Forte@Sun.COM 	    sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN);
14817836SJohn.Forte@Sun.COM 	if (prop.p_alias_len > 0) {
14827836SJohn.Forte@Sun.COM 		(void) mbstowcs(pProps->alias, (char *)prop.p_alias,
14837836SJohn.Forte@Sun.COM 		    IMA_NODE_ALIAS_LEN);
14847836SJohn.Forte@Sun.COM 	}
14857836SJohn.Forte@Sun.COM 
14867836SJohn.Forte@Sun.COM 	/* Initialize the discovery method to unknown method. */
14877836SJohn.Forte@Sun.COM 	pProps->discoveryMethodFlags = IMA_TARGET_DISCOVERY_METHOD_UNKNOWN;
14887836SJohn.Forte@Sun.COM 	if (!((prop.p_discovery & iSCSIDiscoveryMethodStatic) ^
14897836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodStatic)) {
14907836SJohn.Forte@Sun.COM 		pProps->discoveryMethodFlags |=
14917836SJohn.Forte@Sun.COM 		    IMA_TARGET_DISCOVERY_METHOD_STATIC;
14927836SJohn.Forte@Sun.COM 	}
14937836SJohn.Forte@Sun.COM 
14947836SJohn.Forte@Sun.COM 	if (!((prop.p_discovery & iSCSIDiscoveryMethodSLP) ^
14957836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodSLP)) {
14967836SJohn.Forte@Sun.COM 		pProps->discoveryMethodFlags |=	IMA_TARGET_DISCOVERY_METHOD_SLP;
14977836SJohn.Forte@Sun.COM 	}
14987836SJohn.Forte@Sun.COM 
14997836SJohn.Forte@Sun.COM 	if (!((prop.p_discovery & iSCSIDiscoveryMethodISNS) ^
15007836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodISNS)) {
15017836SJohn.Forte@Sun.COM 		pProps->discoveryMethodFlags |=	iSCSIDiscoveryMethodISNS;
15027836SJohn.Forte@Sun.COM 	}
15037836SJohn.Forte@Sun.COM 
15047836SJohn.Forte@Sun.COM 	if (!((prop.p_discovery & iSCSIDiscoveryMethodSendTargets) ^
15057836SJohn.Forte@Sun.COM 	    iSCSIDiscoveryMethodSendTargets)) {
15067836SJohn.Forte@Sun.COM 		pProps->discoveryMethodFlags |= iSCSIDiscoveryMethodSendTargets;
15077836SJohn.Forte@Sun.COM 	}
15087836SJohn.Forte@Sun.COM 
15097836SJohn.Forte@Sun.COM 	(void) close(fd);
15107836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
15117836SJohn.Forte@Sun.COM }
15127836SJohn.Forte@Sun.COM 
15137836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetTargetErrorStatistics(IMA_OID targetId,IMA_TARGET_ERROR_STATISTICS * pStats)15147836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetTargetErrorStatistics(
15157836SJohn.Forte@Sun.COM 		IMA_OID targetId,
15167836SJohn.Forte@Sun.COM 		IMA_TARGET_ERROR_STATISTICS *pStats
15177836SJohn.Forte@Sun.COM )
15187836SJohn.Forte@Sun.COM {
15197836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
15207836SJohn.Forte@Sun.COM }
15217836SJohn.Forte@Sun.COM 
IMA_GetLuOidList(IMA_OID oid,IMA_OID_LIST ** ppList)15227836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetLuOidList(
15237836SJohn.Forte@Sun.COM 		IMA_OID oid,
15247836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
15257836SJohn.Forte@Sun.COM )
15267836SJohn.Forte@Sun.COM {
15277836SJohn.Forte@Sun.COM 	IMA_STATUS		status;
15287836SJohn.Forte@Sun.COM 	int			i;
15297836SJohn.Forte@Sun.COM 	iscsi_lun_list_t	*pLunList;
15307836SJohn.Forte@Sun.COM 
15317836SJohn.Forte@Sun.COM 	if (oid.objectType == IMA_OBJECT_TYPE_LHBA) {
15327836SJohn.Forte@Sun.COM 		status = get_target_lun_oid_list(NULL, &pLunList);
15337836SJohn.Forte@Sun.COM 	} else {
15347836SJohn.Forte@Sun.COM 		status = get_target_lun_oid_list(&oid, &pLunList);
15357836SJohn.Forte@Sun.COM 	}
15367836SJohn.Forte@Sun.COM 
15377836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
15387836SJohn.Forte@Sun.COM 		return (status);
15397836SJohn.Forte@Sun.COM 	}
15407836SJohn.Forte@Sun.COM 
15417836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST) +
15427836SJohn.Forte@Sun.COM 	    (pLunList->ll_out_cnt * sizeof (IMA_OID))));
15437836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
15447836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
15457836SJohn.Forte@Sun.COM 	}
15467836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = pLunList->ll_out_cnt;
15477836SJohn.Forte@Sun.COM 	for (i = 0; i < pLunList->ll_out_cnt; i++) {
15487836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_LU;
15497836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].ownerId = pluginOwnerId;
15507836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].objectSequenceNumber =
15517836SJohn.Forte@Sun.COM 		    pLunList->ll_luns[i].l_oid;
15527836SJohn.Forte@Sun.COM 	}
15537836SJohn.Forte@Sun.COM 
15547836SJohn.Forte@Sun.COM 	free(pLunList);
15557836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
15567836SJohn.Forte@Sun.COM }
15577836SJohn.Forte@Sun.COM 
IMA_GetLuOid(IMA_OID targetId,IMA_UINT64 lun,IMA_OID * pluId)15587836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetLuOid(
15597836SJohn.Forte@Sun.COM 		IMA_OID targetId,
15607836SJohn.Forte@Sun.COM 		IMA_UINT64 lun,
15617836SJohn.Forte@Sun.COM 		IMA_OID *pluId
15627836SJohn.Forte@Sun.COM )
15637836SJohn.Forte@Sun.COM {
15647836SJohn.Forte@Sun.COM 	IMA_STATUS		status;
15657836SJohn.Forte@Sun.COM 	int			i;
15667836SJohn.Forte@Sun.COM 	iscsi_lun_list_t	*pLunList;
15677836SJohn.Forte@Sun.COM 
15687836SJohn.Forte@Sun.COM 	status = get_target_lun_oid_list(&targetId, &pLunList);
15697836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
15707836SJohn.Forte@Sun.COM 		return (status);
15717836SJohn.Forte@Sun.COM 	}
15727836SJohn.Forte@Sun.COM 
15737836SJohn.Forte@Sun.COM 	for (i = 0; i < pLunList->ll_out_cnt; i++) {
15747836SJohn.Forte@Sun.COM 		if (pLunList->ll_luns[i].l_num == lun) {
15757836SJohn.Forte@Sun.COM 			pluId->objectType = IMA_OBJECT_TYPE_LU;
15767836SJohn.Forte@Sun.COM 			pluId->ownerId = pluginOwnerId;
15777836SJohn.Forte@Sun.COM 			pluId->objectSequenceNumber =
15787836SJohn.Forte@Sun.COM 			    pLunList->ll_luns[i].l_oid;
15797836SJohn.Forte@Sun.COM 			free(pLunList);
15807836SJohn.Forte@Sun.COM 			return (IMA_STATUS_SUCCESS);
15817836SJohn.Forte@Sun.COM 		}
15827836SJohn.Forte@Sun.COM 	}
15837836SJohn.Forte@Sun.COM 
15847836SJohn.Forte@Sun.COM 	free(pLunList);
15857836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
15867836SJohn.Forte@Sun.COM }
15877836SJohn.Forte@Sun.COM 
IMA_GetLuProperties(IMA_OID luId,IMA_LU_PROPERTIES * pProps)15887836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetLuProperties(
15897836SJohn.Forte@Sun.COM 		IMA_OID luId,
15907836SJohn.Forte@Sun.COM 		IMA_LU_PROPERTIES *pProps
15917836SJohn.Forte@Sun.COM )
15927836SJohn.Forte@Sun.COM {
15937836SJohn.Forte@Sun.COM 	return (getLuProperties(luId, pProps));
15947836SJohn.Forte@Sun.COM }
15957836SJohn.Forte@Sun.COM 
getLuProperties(IMA_OID luId,IMA_LU_PROPERTIES * pProps)15967836SJohn.Forte@Sun.COM static IMA_STATUS getLuProperties(
15977836SJohn.Forte@Sun.COM 		IMA_OID luId,
15987836SJohn.Forte@Sun.COM 		IMA_LU_PROPERTIES *pProps
15997836SJohn.Forte@Sun.COM )
16007836SJohn.Forte@Sun.COM {
16017836SJohn.Forte@Sun.COM 	IMA_STATUS		status;
16027836SJohn.Forte@Sun.COM 	iscsi_lun_list_t	*pLunList;
16037836SJohn.Forte@Sun.COM 	int			j;
16047836SJohn.Forte@Sun.COM 	IMA_BOOL		lunMatch = IMA_FALSE;
16057836SJohn.Forte@Sun.COM 	int			fd;
16067836SJohn.Forte@Sun.COM 	iscsi_lun_props_t	lun;
16077836SJohn.Forte@Sun.COM 	di_devlink_handle_t	hdl;
16087836SJohn.Forte@Sun.COM 
16097836SJohn.Forte@Sun.COM 	if (luId.objectType != IMA_OBJECT_TYPE_LU) {
16107836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
16117836SJohn.Forte@Sun.COM 	}
16127836SJohn.Forte@Sun.COM 
16137836SJohn.Forte@Sun.COM 	/*
16147836SJohn.Forte@Sun.COM 	 * get list of lun oids for all targets
16157836SJohn.Forte@Sun.COM 	 */
16167836SJohn.Forte@Sun.COM 	status = get_target_lun_oid_list(NULL, &pLunList);
16177836SJohn.Forte@Sun.COM 	if (!IMA_SUCCESS(status)) {
16187836SJohn.Forte@Sun.COM 		return (status);
16197836SJohn.Forte@Sun.COM 	}
16207836SJohn.Forte@Sun.COM 	for (j = 0; j < pLunList->ll_out_cnt; j++) {
16217836SJohn.Forte@Sun.COM 		/*
16227836SJohn.Forte@Sun.COM 		 * for each lun, check if match is found
16237836SJohn.Forte@Sun.COM 		 */
16247836SJohn.Forte@Sun.COM 		if (pLunList->ll_luns[j].l_oid == luId.objectSequenceNumber) {
16257836SJohn.Forte@Sun.COM 			/*
16267836SJohn.Forte@Sun.COM 			 * match found, break out of lun loop
16277836SJohn.Forte@Sun.COM 			 */
16287836SJohn.Forte@Sun.COM 			lunMatch = IMA_TRUE;
16297836SJohn.Forte@Sun.COM 			break;
16307836SJohn.Forte@Sun.COM 		}
16317836SJohn.Forte@Sun.COM 	}
16327836SJohn.Forte@Sun.COM 
16337836SJohn.Forte@Sun.COM 	if (lunMatch == IMA_TRUE) {
16347836SJohn.Forte@Sun.COM 		(void) memset(&lun, 0, sizeof (iscsi_lun_props_t));
16357836SJohn.Forte@Sun.COM 		lun.lp_vers = ISCSI_INTERFACE_VERSION;
16367836SJohn.Forte@Sun.COM 		lun.lp_tgt_oid = pLunList->ll_luns[j].l_tgt_oid;
16377836SJohn.Forte@Sun.COM 		lun.lp_oid = pLunList->ll_luns[j].l_oid;
16387836SJohn.Forte@Sun.COM 	}
16397836SJohn.Forte@Sun.COM 
16407836SJohn.Forte@Sun.COM 	free(pLunList);
16417836SJohn.Forte@Sun.COM 
16427836SJohn.Forte@Sun.COM 	if (lunMatch == IMA_FALSE) {
16437836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
16447836SJohn.Forte@Sun.COM 	}
16457836SJohn.Forte@Sun.COM 
16467836SJohn.Forte@Sun.COM 	/*
16477836SJohn.Forte@Sun.COM 	 * get lun properties
16487836SJohn.Forte@Sun.COM 	 */
16497836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
16507836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
16517836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
16527836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
16537836SJohn.Forte@Sun.COM 	}
16547836SJohn.Forte@Sun.COM 
16557836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_LUN_PROPS_GET, &lun)) {
16567836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
16577836SJohn.Forte@Sun.COM 		    "ISCSI_LUN_PROPS_GET ioctl failed, errno: %d", errno);
16587836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
16597836SJohn.Forte@Sun.COM 	}
16607836SJohn.Forte@Sun.COM 	(void) close(fd);
16617836SJohn.Forte@Sun.COM 
16627836SJohn.Forte@Sun.COM 	/*
16637836SJohn.Forte@Sun.COM 	 * set property values
16647836SJohn.Forte@Sun.COM 	 */
16657836SJohn.Forte@Sun.COM 	pProps->associatedTargetOid.objectType = IMA_OBJECT_TYPE_TARGET;
16667836SJohn.Forte@Sun.COM 	pProps->associatedTargetOid.ownerId = pluginOwnerId;
16677836SJohn.Forte@Sun.COM 	pProps->associatedTargetOid.objectSequenceNumber = lun.lp_tgt_oid;
16687836SJohn.Forte@Sun.COM 	pProps->targetLun = (IMA_UINT64)lun.lp_num;
16697836SJohn.Forte@Sun.COM 	pProps->exposedToOs = IMA_TRUE;
16707836SJohn.Forte@Sun.COM 	(void) memset(&pProps->timeExposedToOs, 0,
16717836SJohn.Forte@Sun.COM 	    sizeof (pProps->timeExposedToOs));
16727836SJohn.Forte@Sun.COM 
16737836SJohn.Forte@Sun.COM 	if (lun.lp_status == LunValid) {
16747836SJohn.Forte@Sun.COM 
16757836SJohn.Forte@Sun.COM 		/* add minor device delimiter */
16767836SJohn.Forte@Sun.COM 		(void) strcat(lun.lp_pathname, ":");
16777836SJohn.Forte@Sun.COM 
16787836SJohn.Forte@Sun.COM 		if ((strstr(lun.lp_pathname, "sd@") != NULL) ||
16797836SJohn.Forte@Sun.COM 		    (strstr(lun.lp_pathname, "ssd@") != NULL) ||
16807836SJohn.Forte@Sun.COM 		    (strstr(lun.lp_pathname, "disk@") != NULL)) {
16817836SJohn.Forte@Sun.COM 			/*
16827836SJohn.Forte@Sun.COM 			 * modify returned pathname to obtain the 2nd slice
16837836SJohn.Forte@Sun.COM 			 * of the raw disk
16847836SJohn.Forte@Sun.COM 			 */
16857836SJohn.Forte@Sun.COM 			(void) strcat(lun.lp_pathname, "c,raw");
16867836SJohn.Forte@Sun.COM 		}
16877836SJohn.Forte@Sun.COM 
16887836SJohn.Forte@Sun.COM 		/*
16897836SJohn.Forte@Sun.COM 		 * Pathname returned by driver is the physical device path.
16907836SJohn.Forte@Sun.COM 		 * This name needs to be converted to the OS device name.
16917836SJohn.Forte@Sun.COM 		 */
16927836SJohn.Forte@Sun.COM 		if (hdl = di_devlink_init(lun.lp_pathname, DI_MAKE_LINK)) {
16937836SJohn.Forte@Sun.COM 			pProps->osDeviceName[0] = L'\0';
16947836SJohn.Forte@Sun.COM 			(void) di_devlink_walk(hdl, NULL, lun.lp_pathname,
16957836SJohn.Forte@Sun.COM 			    DI_PRIMARY_LINK, (void *)pProps->osDeviceName,
16967836SJohn.Forte@Sun.COM 			    get_lun_devlink);
16977836SJohn.Forte@Sun.COM 			if (pProps->osDeviceName[0] != L'\0') {
16987836SJohn.Forte@Sun.COM 				/* OS device name synchronously made */
16997836SJohn.Forte@Sun.COM 				pProps->osDeviceNameValid = IMA_TRUE;
17007836SJohn.Forte@Sun.COM 			} else {
17017836SJohn.Forte@Sun.COM 				pProps->osDeviceNameValid = IMA_FALSE;
17027836SJohn.Forte@Sun.COM 			}
17037836SJohn.Forte@Sun.COM 
17047836SJohn.Forte@Sun.COM 			(void) di_devlink_fini(&hdl);
17057836SJohn.Forte@Sun.COM 		} else {
17067836SJohn.Forte@Sun.COM 			pProps->osDeviceNameValid = IMA_FALSE;
17077836SJohn.Forte@Sun.COM 		}
17087836SJohn.Forte@Sun.COM 
17097836SJohn.Forte@Sun.COM 	} else {
17107836SJohn.Forte@Sun.COM 		pProps->osDeviceNameValid = IMA_FALSE;
17117836SJohn.Forte@Sun.COM 	}
17127836SJohn.Forte@Sun.COM 
17137836SJohn.Forte@Sun.COM 	pProps->osParallelIdsValid = IMA_FALSE;
17147836SJohn.Forte@Sun.COM 
17157836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
17167836SJohn.Forte@Sun.COM }
17177836SJohn.Forte@Sun.COM 
17187836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetStatisticsProperties(IMA_OID oid,IMA_STATISTICS_PROPERTIES * pProps)17197836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetStatisticsProperties(
17207836SJohn.Forte@Sun.COM 		IMA_OID oid,
17217836SJohn.Forte@Sun.COM 		IMA_STATISTICS_PROPERTIES *pProps
17227836SJohn.Forte@Sun.COM )
17237836SJohn.Forte@Sun.COM {
17247836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
17257836SJohn.Forte@Sun.COM }
17267836SJohn.Forte@Sun.COM 
17277836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetDeviceStatistics(IMA_OID luId,IMA_DEVICE_STATISTICS * pStats)17287836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetDeviceStatistics(
17297836SJohn.Forte@Sun.COM 		IMA_OID luId,
17307836SJohn.Forte@Sun.COM 		IMA_DEVICE_STATISTICS *pStats
17317836SJohn.Forte@Sun.COM )
17327836SJohn.Forte@Sun.COM {
17337836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
17347836SJohn.Forte@Sun.COM }
17357836SJohn.Forte@Sun.COM 
IMA_LuInquiry(IMA_OID deviceId,IMA_BOOL evpd,IMA_BOOL cmddt,IMA_BYTE pageCode,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)17367836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_LuInquiry(
17377836SJohn.Forte@Sun.COM 	IMA_OID deviceId,
17387836SJohn.Forte@Sun.COM 	IMA_BOOL evpd,
17397836SJohn.Forte@Sun.COM 	IMA_BOOL cmddt,
17407836SJohn.Forte@Sun.COM 	IMA_BYTE pageCode,
17417836SJohn.Forte@Sun.COM 	IMA_BYTE *pOutputBuffer,
17427836SJohn.Forte@Sun.COM 	IMA_UINT *pOutputBufferLength,
17437836SJohn.Forte@Sun.COM 	IMA_BYTE *pSenseBuffer,
17447836SJohn.Forte@Sun.COM 	IMA_UINT *pSenseBufferLength
17457836SJohn.Forte@Sun.COM )
17467836SJohn.Forte@Sun.COM {
17477836SJohn.Forte@Sun.COM 	IMA_LU_PROPERTIES luProps;
17487836SJohn.Forte@Sun.COM 	IMA_STATUS status;
174911271SMilos.Muzik@Sun.COM 	unsigned char cmdblk[CDB_GROUP0];
175011271SMilos.Muzik@Sun.COM 	IMA_UINT buflen;
17517836SJohn.Forte@Sun.COM 	int fd;
17527836SJohn.Forte@Sun.COM 	iscsi_uscsi_t uscsi;
17537836SJohn.Forte@Sun.COM 
175411271SMilos.Muzik@Sun.COM 	(void) memset(&cmdblk[0], 0, CDB_GROUP0);
175511271SMilos.Muzik@Sun.COM 	cmdblk[0] = SCMD_INQUIRY;
175611271SMilos.Muzik@Sun.COM 
175711271SMilos.Muzik@Sun.COM 	if (evpd == IMA_TRUE)
175811271SMilos.Muzik@Sun.COM 		cmdblk[1] |= 0x01;
175911271SMilos.Muzik@Sun.COM 	if (cmddt == IMA_TRUE)
176011271SMilos.Muzik@Sun.COM 		cmdblk[1] |= 0x02;
176111271SMilos.Muzik@Sun.COM 
17627836SJohn.Forte@Sun.COM 	cmdblk[2] = pageCode;
17637836SJohn.Forte@Sun.COM 
176411271SMilos.Muzik@Sun.COM 	if (*pOutputBufferLength > MAX_INQUIRY_BUFFER_LEN) {
176511271SMilos.Muzik@Sun.COM 		buflen = MAX_INQUIRY_BUFFER_LEN;
176611271SMilos.Muzik@Sun.COM 	} else {
176711271SMilos.Muzik@Sun.COM 		buflen = *pOutputBufferLength;
176811271SMilos.Muzik@Sun.COM 	}
176911271SMilos.Muzik@Sun.COM 	cmdblk[3] = (buflen & 0xff00) >> 8;
177011271SMilos.Muzik@Sun.COM 	cmdblk[4] = (buflen & 0x00ff);
177111271SMilos.Muzik@Sun.COM 
17727836SJohn.Forte@Sun.COM 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
17737836SJohn.Forte@Sun.COM 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
17747836SJohn.Forte@Sun.COM 
17757836SJohn.Forte@Sun.COM 	/* iu_oid is a session oid in the driver */
17767836SJohn.Forte@Sun.COM 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
17777836SJohn.Forte@Sun.COM 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
17787836SJohn.Forte@Sun.COM 		uscsi.iu_lun	= 0;
17797836SJohn.Forte@Sun.COM 	} else {
17807836SJohn.Forte@Sun.COM 		/*
17817836SJohn.Forte@Sun.COM 		 * Get LU properties and associated session oid
17827836SJohn.Forte@Sun.COM 		 * for this lun(deviceId) and put in uscsi.iu_oid
17837836SJohn.Forte@Sun.COM 		 */
17847836SJohn.Forte@Sun.COM 		status = getLuProperties(deviceId, &luProps);
17857836SJohn.Forte@Sun.COM 		if (status != IMA_STATUS_SUCCESS) {
17867836SJohn.Forte@Sun.COM 			return (status);
17877836SJohn.Forte@Sun.COM 		}
17887836SJohn.Forte@Sun.COM 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
17897836SJohn.Forte@Sun.COM 		    objectSequenceNumber;
17907836SJohn.Forte@Sun.COM 		uscsi.iu_lun = luProps.targetLun;
17917836SJohn.Forte@Sun.COM 	}
17927836SJohn.Forte@Sun.COM 
17937836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
17947836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
17957836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
179611271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_buflen = buflen;
17977836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
179811271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
179911271SMilos.Muzik@Sun.COM 	    *pSenseBufferLength : 0;
180011271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
180111271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdblen = CDB_GROUP0;
18027836SJohn.Forte@Sun.COM 
18037836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
18047836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
18057836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
18067836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
18077836SJohn.Forte@Sun.COM 	}
18087836SJohn.Forte@Sun.COM 
18097836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
18107836SJohn.Forte@Sun.COM 		(void) close(fd);
18117836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
18127836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
18137836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
18147836SJohn.Forte@Sun.COM 	}
18157836SJohn.Forte@Sun.COM 
181611271SMilos.Muzik@Sun.COM 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
181711271SMilos.Muzik@Sun.COM 		if (pSenseBufferLength != NULL) {
181811271SMilos.Muzik@Sun.COM 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
181911271SMilos.Muzik@Sun.COM 		}
182011271SMilos.Muzik@Sun.COM 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
182111271SMilos.Muzik@Sun.COM 	}
182211271SMilos.Muzik@Sun.COM 
182311271SMilos.Muzik@Sun.COM 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
18247836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
18257836SJohn.Forte@Sun.COM }
18267836SJohn.Forte@Sun.COM 
IMA_LuReadCapacity(IMA_OID deviceId,IMA_UINT cdbLength,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)18277836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_LuReadCapacity(
18287836SJohn.Forte@Sun.COM 		IMA_OID deviceId,
18297836SJohn.Forte@Sun.COM 		IMA_UINT cdbLength,
18307836SJohn.Forte@Sun.COM 		IMA_BYTE *pOutputBuffer,
18317836SJohn.Forte@Sun.COM 		IMA_UINT *pOutputBufferLength,
18327836SJohn.Forte@Sun.COM 
18337836SJohn.Forte@Sun.COM 		IMA_BYTE *pSenseBuffer,
18347836SJohn.Forte@Sun.COM 		IMA_UINT *pSenseBufferLength
18357836SJohn.Forte@Sun.COM )
18367836SJohn.Forte@Sun.COM {
18377836SJohn.Forte@Sun.COM 	IMA_LU_PROPERTIES luProps;
18387836SJohn.Forte@Sun.COM 	IMA_STATUS status;
183911271SMilos.Muzik@Sun.COM 	/* CDB_GROUP4 size is safe for both 10 and 16 byte CDBs */
184011271SMilos.Muzik@Sun.COM 	unsigned char cmdblk[CDB_GROUP4];
184111271SMilos.Muzik@Sun.COM 	IMA_UINT buflen;
18427836SJohn.Forte@Sun.COM 	int fd;
18437836SJohn.Forte@Sun.COM 	iscsi_uscsi_t uscsi;
18447836SJohn.Forte@Sun.COM 
184511271SMilos.Muzik@Sun.COM 	(void) memset(&cmdblk[0], 0, CDB_GROUP4);
184611271SMilos.Muzik@Sun.COM 
184711271SMilos.Muzik@Sun.COM 	if (cdbLength == CDB_GROUP1) {
184811271SMilos.Muzik@Sun.COM 		/* Read Capacity (10) command. */
184911271SMilos.Muzik@Sun.COM 		cmdblk[0] = SCMD_READ_CAPACITY;
185011271SMilos.Muzik@Sun.COM 		buflen = *pOutputBufferLength;
185111271SMilos.Muzik@Sun.COM 	} else if (cdbLength == CDB_GROUP4) {
185211271SMilos.Muzik@Sun.COM 		/*
185311271SMilos.Muzik@Sun.COM 		 * Read Capacity (16) is a Service Action In command. One
185411271SMilos.Muzik@Sun.COM 		 * command byte (0x9E) is overloaded for multiple operations,
185511271SMilos.Muzik@Sun.COM 		 * with the second CDB byte specifying the desired operation.
185611271SMilos.Muzik@Sun.COM 		 */
185711271SMilos.Muzik@Sun.COM 		cmdblk[0] = SCMD_SVC_ACTION_IN_G4;
185811271SMilos.Muzik@Sun.COM 		cmdblk[1] = SSVC_ACTION_READ_CAPACITY_G4;
185911271SMilos.Muzik@Sun.COM 
186011271SMilos.Muzik@Sun.COM 		if (*pOutputBufferLength > MAX_READ_CAPACITY16_BUFFER_LEN) {
186111271SMilos.Muzik@Sun.COM 			buflen = MAX_READ_CAPACITY16_BUFFER_LEN;
186211271SMilos.Muzik@Sun.COM 		} else {
186311271SMilos.Muzik@Sun.COM 			buflen = *pOutputBufferLength;
186411271SMilos.Muzik@Sun.COM 		}
186511271SMilos.Muzik@Sun.COM 		cmdblk[10] = (buflen & 0xff000000) >> 24;
186611271SMilos.Muzik@Sun.COM 		cmdblk[11] = (buflen & 0x00ff0000) >> 16;
186711271SMilos.Muzik@Sun.COM 		cmdblk[12] = (buflen & 0x0000ff00) >> 8;
186811271SMilos.Muzik@Sun.COM 		cmdblk[13] = (buflen & 0x000000ff);
186911271SMilos.Muzik@Sun.COM 	} else {
187011271SMilos.Muzik@Sun.COM 		/* only 10 and 16 byte CDB are supported */
187111271SMilos.Muzik@Sun.COM 		return (IMA_ERROR_NOT_SUPPORTED);
187211271SMilos.Muzik@Sun.COM 	}
18737836SJohn.Forte@Sun.COM 
18747836SJohn.Forte@Sun.COM 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
18757836SJohn.Forte@Sun.COM 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
18767836SJohn.Forte@Sun.COM 
18777836SJohn.Forte@Sun.COM 	/* iu_oid is a session oid in the driver */
18787836SJohn.Forte@Sun.COM 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
18797836SJohn.Forte@Sun.COM 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
18807836SJohn.Forte@Sun.COM 		uscsi.iu_lun	= 0;
18817836SJohn.Forte@Sun.COM 	} else {
18827836SJohn.Forte@Sun.COM 		/*
18837836SJohn.Forte@Sun.COM 		 * Get LU properties and associated session oid
18847836SJohn.Forte@Sun.COM 		 * for this lun(deviceId) and put in uscsi.iu_oid
18857836SJohn.Forte@Sun.COM 		 */
18867836SJohn.Forte@Sun.COM 		status = getLuProperties(deviceId, &luProps);
18877836SJohn.Forte@Sun.COM 		if (status != IMA_STATUS_SUCCESS) {
18887836SJohn.Forte@Sun.COM 			return (status);
18897836SJohn.Forte@Sun.COM 		}
18907836SJohn.Forte@Sun.COM 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
18917836SJohn.Forte@Sun.COM 		    objectSequenceNumber;
18927836SJohn.Forte@Sun.COM 		uscsi.iu_lun = luProps.targetLun;
18937836SJohn.Forte@Sun.COM 	}
18947836SJohn.Forte@Sun.COM 
18957836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
189611271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
18977836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
189811271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_buflen = buflen;
18997836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
190011271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
190111271SMilos.Muzik@Sun.COM 	    *pSenseBufferLength : 0;
190211271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
190311271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdblen = cdbLength;
19047836SJohn.Forte@Sun.COM 
19057836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
19067836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
19077836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
19087836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
19097836SJohn.Forte@Sun.COM 	}
19107836SJohn.Forte@Sun.COM 
19117836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
19127836SJohn.Forte@Sun.COM 		(void) close(fd);
19137836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
19147836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
19157836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
19167836SJohn.Forte@Sun.COM 	}
19177836SJohn.Forte@Sun.COM 
191811271SMilos.Muzik@Sun.COM 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
191911271SMilos.Muzik@Sun.COM 		if (pSenseBufferLength != NULL) {
192011271SMilos.Muzik@Sun.COM 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
192111271SMilos.Muzik@Sun.COM 		}
192211271SMilos.Muzik@Sun.COM 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
192311271SMilos.Muzik@Sun.COM 	}
192411271SMilos.Muzik@Sun.COM 
192511271SMilos.Muzik@Sun.COM 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
19267836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
19277836SJohn.Forte@Sun.COM }
19287836SJohn.Forte@Sun.COM 
IMA_LuReportLuns(IMA_OID deviceId,IMA_BOOL sendToWellKnownLun,IMA_BYTE selectReport,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)19297836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_LuReportLuns(
19307836SJohn.Forte@Sun.COM 		IMA_OID deviceId,
19317836SJohn.Forte@Sun.COM 		IMA_BOOL sendToWellKnownLun,
19327836SJohn.Forte@Sun.COM 		IMA_BYTE selectReport,
19337836SJohn.Forte@Sun.COM 
19347836SJohn.Forte@Sun.COM 		IMA_BYTE *pOutputBuffer,
19357836SJohn.Forte@Sun.COM 		IMA_UINT *pOutputBufferLength,
19367836SJohn.Forte@Sun.COM 
19377836SJohn.Forte@Sun.COM 		IMA_BYTE *pSenseBuffer,
19387836SJohn.Forte@Sun.COM 		IMA_UINT *pSenseBufferLength
19397836SJohn.Forte@Sun.COM )
19407836SJohn.Forte@Sun.COM {
19417836SJohn.Forte@Sun.COM 	IMA_LU_PROPERTIES luProps;
19427836SJohn.Forte@Sun.COM 	IMA_STATUS status;
194311271SMilos.Muzik@Sun.COM 	unsigned char cmdblk[CDB_GROUP5];
194411271SMilos.Muzik@Sun.COM 	IMA_UINT buflen;
19457836SJohn.Forte@Sun.COM 	int fd;
19467836SJohn.Forte@Sun.COM 	iscsi_uscsi_t uscsi;
19477836SJohn.Forte@Sun.COM 
194811271SMilos.Muzik@Sun.COM 	(void) memset(&cmdblk[0], 0, CDB_GROUP5);
194911271SMilos.Muzik@Sun.COM 	cmdblk[0] = SCMD_REPORT_LUNS;
195011271SMilos.Muzik@Sun.COM 	cmdblk[2] = selectReport;
195111271SMilos.Muzik@Sun.COM 
195211271SMilos.Muzik@Sun.COM 	if (*pOutputBufferLength > MAX_REPORT_LUNS_BUFFER_LEN) {
195311271SMilos.Muzik@Sun.COM 		buflen = MAX_REPORT_LUNS_BUFFER_LEN;
195411271SMilos.Muzik@Sun.COM 	} else {
195511271SMilos.Muzik@Sun.COM 		buflen = *pOutputBufferLength;
195611271SMilos.Muzik@Sun.COM 	}
195711271SMilos.Muzik@Sun.COM 	cmdblk[6] = (buflen & 0xff000000) >> 24;
195811271SMilos.Muzik@Sun.COM 	cmdblk[7] = (buflen & 0x00ff0000) >> 16;
195911271SMilos.Muzik@Sun.COM 	cmdblk[8] = (buflen & 0x0000ff00) >> 8;
196011271SMilos.Muzik@Sun.COM 	cmdblk[9] = (buflen & 0x000000ff);
19617836SJohn.Forte@Sun.COM 
19627836SJohn.Forte@Sun.COM 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
19637836SJohn.Forte@Sun.COM 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
19647836SJohn.Forte@Sun.COM 
19657836SJohn.Forte@Sun.COM 	/* iu_oid is a session oid in the driver */
19667836SJohn.Forte@Sun.COM 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
196711271SMilos.Muzik@Sun.COM 		if (sendToWellKnownLun == IMA_TRUE) {
196811271SMilos.Muzik@Sun.COM 			/* this optional feature is not supported now */
196911271SMilos.Muzik@Sun.COM 			return (IMA_ERROR_NOT_SUPPORTED);
197011271SMilos.Muzik@Sun.COM 		}
19717836SJohn.Forte@Sun.COM 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
19727836SJohn.Forte@Sun.COM 		uscsi.iu_lun	= 0;
19737836SJohn.Forte@Sun.COM 	} else {
19747836SJohn.Forte@Sun.COM 		/*
19757836SJohn.Forte@Sun.COM 		 * Get LU properties and associated session oid
19767836SJohn.Forte@Sun.COM 		 * for this lun(deviceId) and put in uscsi.iu_oid
19777836SJohn.Forte@Sun.COM 		 */
19787836SJohn.Forte@Sun.COM 		status = getLuProperties(deviceId, &luProps);
19797836SJohn.Forte@Sun.COM 		if (status != IMA_STATUS_SUCCESS) {
19807836SJohn.Forte@Sun.COM 			return (status);
19817836SJohn.Forte@Sun.COM 		}
19827836SJohn.Forte@Sun.COM 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
19837836SJohn.Forte@Sun.COM 		    objectSequenceNumber;
19847836SJohn.Forte@Sun.COM 		uscsi.iu_lun = luProps.targetLun;
19857836SJohn.Forte@Sun.COM 	}
19867836SJohn.Forte@Sun.COM 
19877836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
198811271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
19897836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
199011271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_buflen = buflen;
19917836SJohn.Forte@Sun.COM 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
199211271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
199311271SMilos.Muzik@Sun.COM 	    *pSenseBufferLength : 0;
199411271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
199511271SMilos.Muzik@Sun.COM 	uscsi.iu_ucmd.uscsi_cdblen = CDB_GROUP5;
19967836SJohn.Forte@Sun.COM 
19977836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
19987836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
19997836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
20007836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
20017836SJohn.Forte@Sun.COM 	}
20027836SJohn.Forte@Sun.COM 
20037836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
20047836SJohn.Forte@Sun.COM 		(void) close(fd);
20057836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
20067836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
20077836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
20087836SJohn.Forte@Sun.COM 	}
20097836SJohn.Forte@Sun.COM 
201011271SMilos.Muzik@Sun.COM 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
201111271SMilos.Muzik@Sun.COM 		if (pSenseBufferLength != NULL) {
201211271SMilos.Muzik@Sun.COM 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
201311271SMilos.Muzik@Sun.COM 		}
201411271SMilos.Muzik@Sun.COM 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
201511271SMilos.Muzik@Sun.COM 	}
201611271SMilos.Muzik@Sun.COM 
201711271SMilos.Muzik@Sun.COM 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
20187836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
20197836SJohn.Forte@Sun.COM }
20207836SJohn.Forte@Sun.COM 
20217836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_ExposeLu(IMA_OID luId)20227836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_ExposeLu(
20237836SJohn.Forte@Sun.COM 		IMA_OID luId
20247836SJohn.Forte@Sun.COM )
20257836SJohn.Forte@Sun.COM {
20267836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
20277836SJohn.Forte@Sun.COM }
20287836SJohn.Forte@Sun.COM 
20297836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_UnexposeLu(IMA_OID luId)20307836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_UnexposeLu(
20317836SJohn.Forte@Sun.COM 		IMA_OID luId
20327836SJohn.Forte@Sun.COM )
20337836SJohn.Forte@Sun.COM {
20347836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
20357836SJohn.Forte@Sun.COM }
20367836SJohn.Forte@Sun.COM 
IMA_GetAddressKeys(IMA_OID targetOid,IMA_ADDRESS_KEYS ** ppKeys)20377836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetAddressKeys(
20387836SJohn.Forte@Sun.COM 		IMA_OID targetOid,
20397836SJohn.Forte@Sun.COM 		IMA_ADDRESS_KEYS **ppKeys
20407836SJohn.Forte@Sun.COM )
20417836SJohn.Forte@Sun.COM {
20427836SJohn.Forte@Sun.COM 	IMA_STATUS status;
20437836SJohn.Forte@Sun.COM 	IMA_TARGET_PROPERTIES targetProps;
20447836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDR_PROP_LIST *discAddressList;
20457836SJohn.Forte@Sun.COM 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
20467836SJohn.Forte@Sun.COM 	int i, j, addressKeyCount = 0;
20477836SJohn.Forte@Sun.COM 	int addressKeyIdx = 0;
20487836SJohn.Forte@Sun.COM 
20497836SJohn.Forte@Sun.COM 	status = getTargetProperties(targetOid, &targetProps);
20507836SJohn.Forte@Sun.COM 	if (status != IMA_STATUS_SUCCESS) {
20517836SJohn.Forte@Sun.COM 		return (status);
20527836SJohn.Forte@Sun.COM 	}
20537836SJohn.Forte@Sun.COM 
20547836SJohn.Forte@Sun.COM 	status = getDiscoveryAddressPropertiesList(&discAddressList);
20557836SJohn.Forte@Sun.COM 	if (status != IMA_STATUS_SUCCESS) {
20567836SJohn.Forte@Sun.COM 		return (status);
20577836SJohn.Forte@Sun.COM 	}
20587836SJohn.Forte@Sun.COM 
20597836SJohn.Forte@Sun.COM 	/* Get the number of addresses to allocate */
20607836SJohn.Forte@Sun.COM 	for (i = 0; i < discAddressList->discAddrCount; i++) {
20617836SJohn.Forte@Sun.COM 		(void) sendTargets(discAddressList->props[i].discoveryAddress,
20627836SJohn.Forte@Sun.COM 		    &pList);
20637836SJohn.Forte@Sun.COM 		for (j = 0; j < pList->keyCount; j++) {
20647836SJohn.Forte@Sun.COM 			if (wcsncmp(pList->keys[j].name, targetProps.name,
20657836SJohn.Forte@Sun.COM 			    wslen(pList->keys[j].name)) == 0) {
20667836SJohn.Forte@Sun.COM 				addressKeyCount++;
20677836SJohn.Forte@Sun.COM 			}
20687836SJohn.Forte@Sun.COM 		}
20697836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(pList);
20707836SJohn.Forte@Sun.COM 	}
20717836SJohn.Forte@Sun.COM 
20727836SJohn.Forte@Sun.COM 	*ppKeys = (IMA_ADDRESS_KEYS *)calloc(1, sizeof (IMA_ADDRESS_KEYS) +
20737836SJohn.Forte@Sun.COM 	    addressKeyCount * sizeof (IMA_ADDRESS_KEY));
20747836SJohn.Forte@Sun.COM 	if (*ppKeys == NULL) {
20757836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
20767836SJohn.Forte@Sun.COM 	}
20777836SJohn.Forte@Sun.COM 	(*ppKeys)->addressKeyCount = addressKeyCount;
20787836SJohn.Forte@Sun.COM 	addressKeyIdx = 0;
20797836SJohn.Forte@Sun.COM 
20807836SJohn.Forte@Sun.COM 	for (i = 0; i < discAddressList->discAddrCount; i++) {
20817836SJohn.Forte@Sun.COM 		(void) sendTargets(discAddressList->props[i].discoveryAddress,
20827836SJohn.Forte@Sun.COM 		    &pList);
20837836SJohn.Forte@Sun.COM 		for (j = 0; j < pList->keyCount; j++) {
20847836SJohn.Forte@Sun.COM 			if (wcsncmp(pList->keys[j].name, targetProps.name,
20857836SJohn.Forte@Sun.COM 			    wslen(pList->keys[j].name)) != 0) {
20867836SJohn.Forte@Sun.COM 				continue;
20877836SJohn.Forte@Sun.COM 			}
20887836SJohn.Forte@Sun.COM 
20897836SJohn.Forte@Sun.COM 			bcopy(&(pList->keys[j].address.ipAddress),
20907836SJohn.Forte@Sun.COM 			    &((*ppKeys)->addressKeys[addressKeyIdx].
20917836SJohn.Forte@Sun.COM 			    ipAddress), sizeof (IMA_IP_ADDRESS));
20927836SJohn.Forte@Sun.COM 
20937836SJohn.Forte@Sun.COM 			(*ppKeys)->addressKeys[addressKeyIdx++].portNumber =
20947836SJohn.Forte@Sun.COM 			    pList->keys[j].address.portNumber;
20957836SJohn.Forte@Sun.COM 
20967836SJohn.Forte@Sun.COM 		}
20977836SJohn.Forte@Sun.COM 		(void) IMA_FreeMemory(pList);
20987836SJohn.Forte@Sun.COM 	}
20997836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
21007836SJohn.Forte@Sun.COM }
21017836SJohn.Forte@Sun.COM 
isAuthMethodValid(IMA_OID oid,IMA_AUTHMETHOD method)21027836SJohn.Forte@Sun.COM IMA_BOOL isAuthMethodValid(IMA_OID oid, IMA_AUTHMETHOD method) {
21037836SJohn.Forte@Sun.COM 	IMA_STATUS status;
21047836SJohn.Forte@Sun.COM 	IMA_AUTHMETHOD supportedList[MAX_AUTHMETHODS];
21057836SJohn.Forte@Sun.COM 	IMA_UINT i, supportedCount;
21067836SJohn.Forte@Sun.COM 	IMA_BOOL supported;
21077836SJohn.Forte@Sun.COM 	status = getSupportedAuthMethods(oid, IMA_FALSE, &supportedCount,
21087836SJohn.Forte@Sun.COM 			supportedList);
21097836SJohn.Forte@Sun.COM 	if (status != IMA_STATUS_SUCCESS)
21107836SJohn.Forte@Sun.COM 		return (IMA_FALSE);
21117836SJohn.Forte@Sun.COM 
21127836SJohn.Forte@Sun.COM 	supported = IMA_FALSE;
21137836SJohn.Forte@Sun.COM 	for (i = 0; i < supportedCount; i++) {
21147836SJohn.Forte@Sun.COM 		if (method == supportedList[i]) {
21157836SJohn.Forte@Sun.COM 			supported = IMA_TRUE;
21167836SJohn.Forte@Sun.COM 		}
21177836SJohn.Forte@Sun.COM 	}
21187836SJohn.Forte@Sun.COM 
21197836SJohn.Forte@Sun.COM 	return (supported);
21207836SJohn.Forte@Sun.COM }
21217836SJohn.Forte@Sun.COM 
isAuthMethodListValid(IMA_OID oid,const IMA_AUTHMETHOD * pMethodList,IMA_UINT methodCount)21227836SJohn.Forte@Sun.COM IMA_BOOL isAuthMethodListValid(IMA_OID oid, const IMA_AUTHMETHOD *pMethodList,
21237836SJohn.Forte@Sun.COM 				IMA_UINT methodCount) {
21247836SJohn.Forte@Sun.COM 	IMA_UINT i, j;
21257836SJohn.Forte@Sun.COM 
21267836SJohn.Forte@Sun.COM 	if (pMethodList == NULL) {
21277836SJohn.Forte@Sun.COM 		return (IMA_FALSE);
21287836SJohn.Forte@Sun.COM 	}
21297836SJohn.Forte@Sun.COM 	/* Check list for duplicates */
21307836SJohn.Forte@Sun.COM 	for (i = 0; i < methodCount; i++) {
21317836SJohn.Forte@Sun.COM 		for (j = i + 1; j < methodCount; j++) {
21327836SJohn.Forte@Sun.COM 			if (pMethodList[i] == pMethodList[j]) {
21337836SJohn.Forte@Sun.COM 				return (IMA_FALSE);
21347836SJohn.Forte@Sun.COM 			}
21357836SJohn.Forte@Sun.COM 		}
21367836SJohn.Forte@Sun.COM 
21377836SJohn.Forte@Sun.COM 		if (isAuthMethodValid(oid, pMethodList[i]) == IMA_FALSE) {
21387836SJohn.Forte@Sun.COM 			return (IMA_FALSE);
21397836SJohn.Forte@Sun.COM 		}
21407836SJohn.Forte@Sun.COM 	}
21417836SJohn.Forte@Sun.COM 	return (IMA_TRUE);
21427836SJohn.Forte@Sun.COM }
21437836SJohn.Forte@Sun.COM 
IMA_GetSupportedAuthMethods(IMA_OID lhbaOid,IMA_BOOL getSettableMethods,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)21447836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetSupportedAuthMethods(
21457836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
21467836SJohn.Forte@Sun.COM 		IMA_BOOL getSettableMethods,
21477836SJohn.Forte@Sun.COM 		IMA_UINT *pMethodCount,
21487836SJohn.Forte@Sun.COM 		IMA_AUTHMETHOD *pMethodList
21497836SJohn.Forte@Sun.COM )
21507836SJohn.Forte@Sun.COM {
21517836SJohn.Forte@Sun.COM 	return (getSupportedAuthMethods(lhbaOid, getSettableMethods,
21527836SJohn.Forte@Sun.COM 	    pMethodCount, pMethodList));
21537836SJohn.Forte@Sun.COM }
21547836SJohn.Forte@Sun.COM 
21557836SJohn.Forte@Sun.COM 
21567836SJohn.Forte@Sun.COM /*ARGSUSED*/
getSupportedAuthMethods(IMA_OID lhbaOid,IMA_BOOL getSettableMethods,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)21577836SJohn.Forte@Sun.COM static IMA_STATUS getSupportedAuthMethods(
21587836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
21597836SJohn.Forte@Sun.COM 		IMA_BOOL getSettableMethods,
21607836SJohn.Forte@Sun.COM 		IMA_UINT *pMethodCount,
21617836SJohn.Forte@Sun.COM 		IMA_AUTHMETHOD *pMethodList
21627836SJohn.Forte@Sun.COM )
21637836SJohn.Forte@Sun.COM {
21647836SJohn.Forte@Sun.COM 	if (pMethodList == NULL) {
21657836SJohn.Forte@Sun.COM 		*pMethodCount = 0;
21667836SJohn.Forte@Sun.COM 		return (IMA_STATUS_SUCCESS);
21677836SJohn.Forte@Sun.COM 	}
21687836SJohn.Forte@Sun.COM 
21697836SJohn.Forte@Sun.COM 	*pMethodCount = NUM_SUPPORTED_AUTH_METHODS;
21707836SJohn.Forte@Sun.COM 	if (*pMethodCount > 1) {
21717836SJohn.Forte@Sun.COM 		pMethodList[0] = IMA_AUTHMETHOD_NONE;
21727836SJohn.Forte@Sun.COM 		pMethodList[1] = IMA_AUTHMETHOD_CHAP;
21737836SJohn.Forte@Sun.COM 	}
21747836SJohn.Forte@Sun.COM 
21757836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
21767836SJohn.Forte@Sun.COM }
21777836SJohn.Forte@Sun.COM 
IMA_GetInUseInitiatorAuthMethods(IMA_OID lhbaOid,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)21787836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetInUseInitiatorAuthMethods(
21797836SJohn.Forte@Sun.COM 		IMA_OID		lhbaOid,
21807836SJohn.Forte@Sun.COM 		IMA_UINT	*pMethodCount,
21817836SJohn.Forte@Sun.COM 		IMA_AUTHMETHOD *pMethodList
21827836SJohn.Forte@Sun.COM )
21837836SJohn.Forte@Sun.COM {
21847836SJohn.Forte@Sun.COM 	return (getAuthMethods(lhbaOid, pMethodCount, pMethodList));
21857836SJohn.Forte@Sun.COM }
21867836SJohn.Forte@Sun.COM 
21877836SJohn.Forte@Sun.COM /*ARGSUSED*/
IMA_GetInitiatorAuthParms(IMA_OID lhbaOid,IMA_AUTHMETHOD method,IMA_INITIATOR_AUTHPARMS * pParms)21887836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_GetInitiatorAuthParms(
21897836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
21907836SJohn.Forte@Sun.COM 		IMA_AUTHMETHOD method,
21917836SJohn.Forte@Sun.COM 		IMA_INITIATOR_AUTHPARMS *pParms
21927836SJohn.Forte@Sun.COM )
21937836SJohn.Forte@Sun.COM {
21947836SJohn.Forte@Sun.COM 	int fd;
21957836SJohn.Forte@Sun.COM 	iscsi_chap_props_t  chap_p;
21967836SJohn.Forte@Sun.COM 
21977836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
21987836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
21997836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
22007836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
22017836SJohn.Forte@Sun.COM 	}
22027836SJohn.Forte@Sun.COM 
22037836SJohn.Forte@Sun.COM 	(void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t));
22047836SJohn.Forte@Sun.COM 	chap_p.c_vers = ISCSI_INTERFACE_VERSION;
22057836SJohn.Forte@Sun.COM 	chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber;
22067836SJohn.Forte@Sun.COM 
22077836SJohn.Forte@Sun.COM 	if (method == IMA_AUTHMETHOD_CHAP) {
22087836SJohn.Forte@Sun.COM 		if (ioctl(fd, ISCSI_CHAP_GET, &chap_p) != 0) {
22097836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
22107836SJohn.Forte@Sun.COM 			"ISCSI_CHAP_GET ioctl failed, errno: %d", errno);
22117836SJohn.Forte@Sun.COM 			(void) close(fd);
22127836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
22137836SJohn.Forte@Sun.COM 		}
22147836SJohn.Forte@Sun.COM 	} else {
22157836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
22167836SJohn.Forte@Sun.COM 	}
22177836SJohn.Forte@Sun.COM 
22187836SJohn.Forte@Sun.COM 	(void) memcpy(pParms->chapParms.name, chap_p.c_user,
22197836SJohn.Forte@Sun.COM 	    chap_p.c_user_len);
22207836SJohn.Forte@Sun.COM 	pParms->chapParms.nameLength = chap_p.c_user_len;
22217836SJohn.Forte@Sun.COM 	(void) memcpy(pParms->chapParms.challengeSecret, chap_p.c_secret,
22227836SJohn.Forte@Sun.COM 	    chap_p.c_secret_len);
22237836SJohn.Forte@Sun.COM 	pParms->chapParms.challengeSecretLength = chap_p.c_secret_len;
22247836SJohn.Forte@Sun.COM 
22257836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
22267836SJohn.Forte@Sun.COM }
22277836SJohn.Forte@Sun.COM 
IMA_SetInitiatorAuthMethods(IMA_OID lhbaOid,IMA_UINT methodCount,const IMA_AUTHMETHOD * pMethodList)22287836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetInitiatorAuthMethods(
22297836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
22307836SJohn.Forte@Sun.COM 		IMA_UINT methodCount,
22317836SJohn.Forte@Sun.COM 		const IMA_AUTHMETHOD *pMethodList
22327836SJohn.Forte@Sun.COM )
22337836SJohn.Forte@Sun.COM {
22347836SJohn.Forte@Sun.COM 	if (isAuthMethodListValid(lhbaOid, pMethodList,
22357836SJohn.Forte@Sun.COM 	    methodCount) == IMA_FALSE)
22367836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
22377836SJohn.Forte@Sun.COM 	return (setAuthMethods(lhbaOid, &methodCount, pMethodList));
22387836SJohn.Forte@Sun.COM }
22397836SJohn.Forte@Sun.COM 
22407836SJohn.Forte@Sun.COM /*
22417836SJohn.Forte@Sun.COM  * This function only sets CHAP params since we only support CHAP for now.
22427836SJohn.Forte@Sun.COM  */
IMA_SetInitiatorAuthParms(IMA_OID lhbaOid,IMA_AUTHMETHOD method,const IMA_INITIATOR_AUTHPARMS * pParms)22437836SJohn.Forte@Sun.COM IMA_API	IMA_STATUS IMA_SetInitiatorAuthParms(
22447836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
22457836SJohn.Forte@Sun.COM 		IMA_AUTHMETHOD method,
22467836SJohn.Forte@Sun.COM 		const IMA_INITIATOR_AUTHPARMS *pParms
22477836SJohn.Forte@Sun.COM )
22487836SJohn.Forte@Sun.COM {
22497836SJohn.Forte@Sun.COM 	int fd;
22507836SJohn.Forte@Sun.COM 	iscsi_chap_props_t  chap_p;
22517836SJohn.Forte@Sun.COM 
22527836SJohn.Forte@Sun.COM 	if (method != IMA_AUTHMETHOD_CHAP)
22537836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
22547836SJohn.Forte@Sun.COM 
22557836SJohn.Forte@Sun.COM 	if (isAuthMethodValid(lhbaOid, method) == IMA_FALSE) {
22567836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
22577836SJohn.Forte@Sun.COM 	}
22587836SJohn.Forte@Sun.COM 
22597836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
22607836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
22617836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
22627836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
22637836SJohn.Forte@Sun.COM 	}
22647836SJohn.Forte@Sun.COM 
22657836SJohn.Forte@Sun.COM 	(void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t));
22667836SJohn.Forte@Sun.COM 	chap_p.c_vers = ISCSI_INTERFACE_VERSION;
22677836SJohn.Forte@Sun.COM 	chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber;
22687836SJohn.Forte@Sun.COM 
22697836SJohn.Forte@Sun.COM 	chap_p.c_user_len = pParms->chapParms.nameLength;
22707836SJohn.Forte@Sun.COM 	(void) memcpy(chap_p.c_user, pParms->chapParms.name, chap_p.c_user_len);
22717836SJohn.Forte@Sun.COM 
22727836SJohn.Forte@Sun.COM 	chap_p.c_secret_len = pParms->chapParms.challengeSecretLength;
22737836SJohn.Forte@Sun.COM 	(void) memcpy(chap_p.c_secret, pParms->chapParms.challengeSecret,
22747836SJohn.Forte@Sun.COM 	    chap_p.c_secret_len);
22757836SJohn.Forte@Sun.COM 
22767836SJohn.Forte@Sun.COM 	if (method == IMA_AUTHMETHOD_CHAP) {
22777836SJohn.Forte@Sun.COM 		if (ioctl(fd, ISCSI_CHAP_SET, &chap_p) != 0) {
22787836SJohn.Forte@Sun.COM 			(void) close(fd);
22797836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
22807836SJohn.Forte@Sun.COM 			    "ISCSI_CHAP_SET ioctl failed, errno: %d", errno);
22817836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
22827836SJohn.Forte@Sun.COM 		}
22837836SJohn.Forte@Sun.COM 	}
22847836SJohn.Forte@Sun.COM 
22857836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
22867836SJohn.Forte@Sun.COM }
22877836SJohn.Forte@Sun.COM 
22887836SJohn.Forte@Sun.COM /* A helper function to obtain iSCSI node parameters. */
22897836SJohn.Forte@Sun.COM static IMA_STATUS
getISCSINodeParameter(int paramType,IMA_OID * oid,void * pProps,uint32_t paramIndex)22907836SJohn.Forte@Sun.COM getISCSINodeParameter(
22917836SJohn.Forte@Sun.COM     int paramType,
22927836SJohn.Forte@Sun.COM     IMA_OID *oid,
22937836SJohn.Forte@Sun.COM     void *pProps,
22947836SJohn.Forte@Sun.COM     uint32_t paramIndex
22957836SJohn.Forte@Sun.COM )
22967836SJohn.Forte@Sun.COM {
22977836SJohn.Forte@Sun.COM 	int		    fd;
22987836SJohn.Forte@Sun.COM 	iscsi_param_get_t   pg;
22997836SJohn.Forte@Sun.COM 
23007836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
23017836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
23027836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
23037836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
23047836SJohn.Forte@Sun.COM 	}
23057836SJohn.Forte@Sun.COM 
23067836SJohn.Forte@Sun.COM 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
23077836SJohn.Forte@Sun.COM 	pg.g_vers = ISCSI_INTERFACE_VERSION;
23087836SJohn.Forte@Sun.COM 	pg.g_oid = (uint32_t)oid->objectSequenceNumber;
23097836SJohn.Forte@Sun.COM 	pg.g_param = paramIndex;
23107836SJohn.Forte@Sun.COM 	pg.g_param_type = ISCSI_SESS_PARAM;
23117836SJohn.Forte@Sun.COM 
23127836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) {
23137836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
23147836SJohn.Forte@Sun.COM 		    "ISCSI_PARAM_GET ioctl failed, errno: %d", errno);
23157836SJohn.Forte@Sun.COM 		(void) close(fd);
23167836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
23177836SJohn.Forte@Sun.COM 	}
23187836SJohn.Forte@Sun.COM 
23197836SJohn.Forte@Sun.COM 	switch (paramType) {
23207836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *bp;
23217836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *mp;
23227836SJohn.Forte@Sun.COM 
23237836SJohn.Forte@Sun.COM 		case MIN_MAX_PARAM:
23247836SJohn.Forte@Sun.COM 			mp = (IMA_MIN_MAX_VALUE *)pProps;
23257836SJohn.Forte@Sun.COM 
23267836SJohn.Forte@Sun.COM 			mp->currentValueValid =
23277836SJohn.Forte@Sun.COM 			    (pg.g_value.v_valid == B_TRUE) ?
23287836SJohn.Forte@Sun.COM 			    IMA_TRUE : IMA_FALSE;
23297836SJohn.Forte@Sun.COM 			mp->currentValue = pg.g_value.v_integer.i_current;
23307836SJohn.Forte@Sun.COM 			mp->defaultValue = pg.g_value.v_integer.i_default;
23317836SJohn.Forte@Sun.COM 			mp->minimumValue = pg.g_value.v_integer.i_min;
23327836SJohn.Forte@Sun.COM 			mp->maximumValue = pg.g_value.v_integer.i_max;
23337836SJohn.Forte@Sun.COM 			mp->incrementValue = pg.g_value.v_integer.i_incr;
23347836SJohn.Forte@Sun.COM 			break;
23357836SJohn.Forte@Sun.COM 
23367836SJohn.Forte@Sun.COM 		case BOOL_PARAM:
23377836SJohn.Forte@Sun.COM 			bp = (IMA_BOOL_VALUE *)pProps;
23387836SJohn.Forte@Sun.COM 			bp->currentValueValid =
23397836SJohn.Forte@Sun.COM 			    (pg.g_value.v_valid == B_TRUE) ?
23407836SJohn.Forte@Sun.COM 			    IMA_TRUE : IMA_FALSE;
23417836SJohn.Forte@Sun.COM 			bp->currentValue = pg.g_value.v_bool.b_current;
23427836SJohn.Forte@Sun.COM 			bp->defaultValue = pg.g_value.v_bool.b_default;
23437836SJohn.Forte@Sun.COM 			break;
23447836SJohn.Forte@Sun.COM 
23457836SJohn.Forte@Sun.COM 		default:
23467836SJohn.Forte@Sun.COM 			break;
23477836SJohn.Forte@Sun.COM 	}
23487836SJohn.Forte@Sun.COM 
23497836SJohn.Forte@Sun.COM 	(void) close(fd);
23507836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
23517836SJohn.Forte@Sun.COM }
23527836SJohn.Forte@Sun.COM 
23537836SJohn.Forte@Sun.COM /* A helper function to set iSCSI node parameters. */
23547836SJohn.Forte@Sun.COM static IMA_STATUS
setISCSINodeParameter(int paramType,IMA_OID * oid,void * pProp,uint32_t paramIndex)23557836SJohn.Forte@Sun.COM setISCSINodeParameter(
23567836SJohn.Forte@Sun.COM     int paramType,
23577836SJohn.Forte@Sun.COM     IMA_OID *oid,
23587836SJohn.Forte@Sun.COM     void *pProp,
23597836SJohn.Forte@Sun.COM     uint32_t paramIndex
23607836SJohn.Forte@Sun.COM )
23617836SJohn.Forte@Sun.COM {
23627836SJohn.Forte@Sun.COM 	int		    fd;
23637836SJohn.Forte@Sun.COM 	iscsi_param_set_t   ps;
23647836SJohn.Forte@Sun.COM 
23657836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
23667836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
23677836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
23687836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
23697836SJohn.Forte@Sun.COM 	}
23707836SJohn.Forte@Sun.COM 
23717836SJohn.Forte@Sun.COM 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
23727836SJohn.Forte@Sun.COM 	ps.s_vers = ISCSI_INTERFACE_VERSION;
23737836SJohn.Forte@Sun.COM 	ps.s_oid = (uint32_t)oid->objectSequenceNumber;
23747836SJohn.Forte@Sun.COM 	ps.s_param = paramIndex;
23757836SJohn.Forte@Sun.COM 
23767836SJohn.Forte@Sun.COM 	switch (paramType) {
23777836SJohn.Forte@Sun.COM 		IMA_BOOL_VALUE *bp;
23787836SJohn.Forte@Sun.COM 		IMA_MIN_MAX_VALUE *mp;
23797836SJohn.Forte@Sun.COM 
23807836SJohn.Forte@Sun.COM 		case MIN_MAX_PARAM:
23817836SJohn.Forte@Sun.COM 			mp = (IMA_MIN_MAX_VALUE *)pProp;
23827836SJohn.Forte@Sun.COM 			ps.s_value.v_integer = mp->currentValue;
23837836SJohn.Forte@Sun.COM 			break;
23847836SJohn.Forte@Sun.COM 		case BOOL_PARAM:
23857836SJohn.Forte@Sun.COM 			bp = (IMA_BOOL_VALUE *)pProp;
23867836SJohn.Forte@Sun.COM 			ps.s_value.v_bool =
23877836SJohn.Forte@Sun.COM 			    (bp->currentValue == IMA_TRUE) ?
23887836SJohn.Forte@Sun.COM 			    B_TRUE : B_FALSE;
23897836SJohn.Forte@Sun.COM 			break;
23907836SJohn.Forte@Sun.COM 
23917836SJohn.Forte@Sun.COM 		default:
23927836SJohn.Forte@Sun.COM 			break;
23937836SJohn.Forte@Sun.COM 	}
23947836SJohn.Forte@Sun.COM 
23957836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_PARAM_SET, &ps)) {
23967836SJohn.Forte@Sun.COM 		int tmpErrno = errno;
23977836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
23987836SJohn.Forte@Sun.COM 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
23997836SJohn.Forte@Sun.COM 		(void) close(fd);
24007836SJohn.Forte@Sun.COM 		switch (tmpErrno) {
24017836SJohn.Forte@Sun.COM 			case ENOTSUP :
24027836SJohn.Forte@Sun.COM 				return (IMA_ERROR_NOT_SUPPORTED);
24037836SJohn.Forte@Sun.COM 			default :
24047836SJohn.Forte@Sun.COM 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
24057836SJohn.Forte@Sun.COM 		}
24067836SJohn.Forte@Sun.COM 	}
24077836SJohn.Forte@Sun.COM 
24087836SJohn.Forte@Sun.COM 	(void) close(fd);
24097836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
24107836SJohn.Forte@Sun.COM }
24117836SJohn.Forte@Sun.COM 
24127836SJohn.Forte@Sun.COM static int
prepare_discovery_entry(IMA_TARGET_ADDRESS discoveryAddress,entry_t * entry)24137836SJohn.Forte@Sun.COM prepare_discovery_entry(
24147836SJohn.Forte@Sun.COM     IMA_TARGET_ADDRESS discoveryAddress,
24157836SJohn.Forte@Sun.COM     entry_t *entry
24167836SJohn.Forte@Sun.COM )
24177836SJohn.Forte@Sun.COM {
24187836SJohn.Forte@Sun.COM 	(void) memset(entry, 0, sizeof (entry_t));
24197836SJohn.Forte@Sun.COM 	entry->e_vers = ISCSI_INTERFACE_VERSION;
24207836SJohn.Forte@Sun.COM 	entry->e_oid = ISCSI_OID_NOTSET;
24217836SJohn.Forte@Sun.COM 
24227836SJohn.Forte@Sun.COM 	if (discoveryAddress.hostnameIpAddress.id.ipAddress.ipv4Address ==
24237836SJohn.Forte@Sun.COM 	    IMA_FALSE) {
24247836SJohn.Forte@Sun.COM 		bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
24257836SJohn.Forte@Sun.COM 		    entry->e_u.u_in6.s6_addr,
24267836SJohn.Forte@Sun.COM 		    sizeof (entry->e_u.u_in6.s6_addr));
24277836SJohn.Forte@Sun.COM 		entry->e_insize = sizeof (struct in6_addr);
24287836SJohn.Forte@Sun.COM 	} else {
24297836SJohn.Forte@Sun.COM 		bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
24307836SJohn.Forte@Sun.COM 		    &entry->e_u.u_in4.s_addr,
24317836SJohn.Forte@Sun.COM 		    sizeof (entry->e_u.u_in4.s_addr));
24327836SJohn.Forte@Sun.COM 		entry->e_insize = sizeof (struct in_addr);
24337836SJohn.Forte@Sun.COM 	}
24347836SJohn.Forte@Sun.COM 
24357836SJohn.Forte@Sun.COM 	entry->e_port = discoveryAddress.portNumber;
24367836SJohn.Forte@Sun.COM 	entry->e_tpgt = 0;
24377836SJohn.Forte@Sun.COM 	return (DISC_ADDR_OK);
24387836SJohn.Forte@Sun.COM }
24397836SJohn.Forte@Sun.COM 
configure_discovery_method(IMA_BOOL enable,iSCSIDiscoveryMethod_t method)24407836SJohn.Forte@Sun.COM static IMA_STATUS configure_discovery_method(
24417836SJohn.Forte@Sun.COM     IMA_BOOL enable,
24427836SJohn.Forte@Sun.COM     iSCSIDiscoveryMethod_t method
24437836SJohn.Forte@Sun.COM )
24447836SJohn.Forte@Sun.COM {
24457836SJohn.Forte@Sun.COM 	int fd, status;
24467836SJohn.Forte@Sun.COM 
24477836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
24487836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
24497836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
24507836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
24517836SJohn.Forte@Sun.COM 	}
24527836SJohn.Forte@Sun.COM 
24537836SJohn.Forte@Sun.COM 	if (enable == IMA_FALSE) {
24547836SJohn.Forte@Sun.COM 		if (ioctl(fd, ISCSI_DISCOVERY_CLEAR, &method)) {
24557836SJohn.Forte@Sun.COM 			status = errno;
24567836SJohn.Forte@Sun.COM 			(void) close(fd);
24577836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
24587836SJohn.Forte@Sun.COM 			    "ISCSI_DISCOVERY_CLEAR ioctl failed, errno: %d",
24597836SJohn.Forte@Sun.COM 			    status);
24607836SJohn.Forte@Sun.COM 			if (status == EBUSY) {
24617836SJohn.Forte@Sun.COM 				return (IMA_ERROR_LU_IN_USE);
24627836SJohn.Forte@Sun.COM 			} else {
24637836SJohn.Forte@Sun.COM 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
24647836SJohn.Forte@Sun.COM 			}
24657836SJohn.Forte@Sun.COM 		}
24667836SJohn.Forte@Sun.COM 
24677836SJohn.Forte@Sun.COM 		(void) close(fd);
24687836SJohn.Forte@Sun.COM 		return (IMA_STATUS_SUCCESS);
24697836SJohn.Forte@Sun.COM 	} else {
24707836SJohn.Forte@Sun.COM 		/* Set the discovery method */
24717836SJohn.Forte@Sun.COM 		if (ioctl(fd, ISCSI_DISCOVERY_SET, &method)) {
24727836SJohn.Forte@Sun.COM 			(void) close(fd);
24737836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
24747836SJohn.Forte@Sun.COM 			    "ISCSI_DISCOVERY_SET ioctl failed, errno: %d",
24757836SJohn.Forte@Sun.COM 			    errno);
24767836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
24777836SJohn.Forte@Sun.COM 		}
24787836SJohn.Forte@Sun.COM 
24797836SJohn.Forte@Sun.COM 		(void) close(fd);
24807836SJohn.Forte@Sun.COM 		return (IMA_STATUS_SUCCESS);
24817836SJohn.Forte@Sun.COM 	}
24827836SJohn.Forte@Sun.COM }
24837836SJohn.Forte@Sun.COM 
get_target_oid_list(uint32_t targetListType,IMA_OID_LIST ** ppList)24847836SJohn.Forte@Sun.COM static IMA_STATUS get_target_oid_list(
24857836SJohn.Forte@Sun.COM     uint32_t targetListType,
24867836SJohn.Forte@Sun.COM     IMA_OID_LIST **ppList)
24877836SJohn.Forte@Sun.COM {
24887836SJohn.Forte@Sun.COM 	int		    fd;
24897836SJohn.Forte@Sun.COM 	int		    i;
24907836SJohn.Forte@Sun.COM 	int		    target_list_size;
24917836SJohn.Forte@Sun.COM 	iscsi_target_list_t *idlp, tl_info;
24927836SJohn.Forte@Sun.COM 
24937836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
24947836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
24957836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
24967836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
24977836SJohn.Forte@Sun.COM 	}
24987836SJohn.Forte@Sun.COM 
24997836SJohn.Forte@Sun.COM 	(void) memset(&tl_info, 0, sizeof (tl_info));
25007836SJohn.Forte@Sun.COM 	tl_info.tl_vers = ISCSI_INTERFACE_VERSION;
25017836SJohn.Forte@Sun.COM 	tl_info.tl_in_cnt = 0;
25027836SJohn.Forte@Sun.COM 	tl_info.tl_tgt_list_type = targetListType;
25037836SJohn.Forte@Sun.COM 
25047836SJohn.Forte@Sun.COM 	/*
25057836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the number of targets.
25067836SJohn.Forte@Sun.COM 	 */
25077836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, &tl_info) != 0) {
25087836SJohn.Forte@Sun.COM 		(void) close(fd);
25097836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
25107836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
25117836SJohn.Forte@Sun.COM 		    targetListType, errno);
25127836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
25137836SJohn.Forte@Sun.COM 	}
25147836SJohn.Forte@Sun.COM 
25157836SJohn.Forte@Sun.COM 	target_list_size = sizeof (iscsi_target_list_t);
25167836SJohn.Forte@Sun.COM 	if (tl_info.tl_out_cnt > 1) {
25177836SJohn.Forte@Sun.COM 		target_list_size += (sizeof (uint32_t) *
25187836SJohn.Forte@Sun.COM 		    tl_info.tl_out_cnt - 1);
25197836SJohn.Forte@Sun.COM 	}
25207836SJohn.Forte@Sun.COM 
25217836SJohn.Forte@Sun.COM 	idlp = (iscsi_target_list_t *)calloc(1, target_list_size);
25227836SJohn.Forte@Sun.COM 	if (idlp == NULL) {
25237836SJohn.Forte@Sun.COM 		(void) close(fd);
25247836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
25257836SJohn.Forte@Sun.COM 	}
25267836SJohn.Forte@Sun.COM 
25277836SJohn.Forte@Sun.COM 	idlp->tl_vers = ISCSI_INTERFACE_VERSION;
25287836SJohn.Forte@Sun.COM 	idlp->tl_in_cnt = tl_info.tl_out_cnt;
25297836SJohn.Forte@Sun.COM 	idlp->tl_tgt_list_type = targetListType;
25307836SJohn.Forte@Sun.COM 
25317836SJohn.Forte@Sun.COM 	/* Issue the same ioctl again to obtain the OIDs. */
25327836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) {
25337836SJohn.Forte@Sun.COM 		free(idlp);
25347836SJohn.Forte@Sun.COM 		(void) close(fd);
25357836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
25367836SJohn.Forte@Sun.COM 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
25377836SJohn.Forte@Sun.COM 		    targetListType, errno);
25387836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
25397836SJohn.Forte@Sun.COM 	}
25407836SJohn.Forte@Sun.COM 
25417836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) +
25427836SJohn.Forte@Sun.COM 	    idlp->tl_out_cnt * sizeof (IMA_OID));
25437836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
25447836SJohn.Forte@Sun.COM 		free(idlp);
25457836SJohn.Forte@Sun.COM 		(void) close(fd);
25467836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
25477836SJohn.Forte@Sun.COM 	}
25487836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = idlp->tl_out_cnt;
25497836SJohn.Forte@Sun.COM 
25507836SJohn.Forte@Sun.COM 	for (i = 0; i < idlp->tl_out_cnt; i++) {
25517836SJohn.Forte@Sun.COM 
25527836SJohn.Forte@Sun.COM 		if (targetListType == ISCSI_STATIC_TGT_OID_LIST)
25537836SJohn.Forte@Sun.COM 			(*ppList)->oids[i].objectType =
25547836SJohn.Forte@Sun.COM 			    IMA_OBJECT_TYPE_STATIC_DISCOVERY_TARGET;
25557836SJohn.Forte@Sun.COM 		else
25567836SJohn.Forte@Sun.COM 			(*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_TARGET;
25577836SJohn.Forte@Sun.COM 
25587836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].ownerId = pluginOwnerId;
25597836SJohn.Forte@Sun.COM 		(*ppList)->oids[i].objectSequenceNumber = idlp->tl_oid_list[i];
25607836SJohn.Forte@Sun.COM 	}
25617836SJohn.Forte@Sun.COM 
25627836SJohn.Forte@Sun.COM 	free(idlp);
25637836SJohn.Forte@Sun.COM 	(void) close(fd);
25647836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
25657836SJohn.Forte@Sun.COM }
25667836SJohn.Forte@Sun.COM 
get_target_lun_oid_list(IMA_OID * targetOid,iscsi_lun_list_t ** ppLunList)25677836SJohn.Forte@Sun.COM static IMA_STATUS get_target_lun_oid_list(
25687836SJohn.Forte@Sun.COM     IMA_OID * targetOid,
25697836SJohn.Forte@Sun.COM     iscsi_lun_list_t  **ppLunList)
25707836SJohn.Forte@Sun.COM {
25717836SJohn.Forte@Sun.COM 	int			fd;
25727836SJohn.Forte@Sun.COM 	iscsi_lun_list_t	*illp, ll_info;
25737836SJohn.Forte@Sun.COM 	int			lun_list_size;
25747836SJohn.Forte@Sun.COM 
25757836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
25767836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
25777836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
25787836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
25797836SJohn.Forte@Sun.COM 	}
25807836SJohn.Forte@Sun.COM 
25817836SJohn.Forte@Sun.COM 	(void) memset(&ll_info, 0, sizeof (ll_info));
25827836SJohn.Forte@Sun.COM 	ll_info.ll_vers = ISCSI_INTERFACE_VERSION;
25837836SJohn.Forte@Sun.COM 	if (targetOid == NULL) {
25847836SJohn.Forte@Sun.COM 		/* get lun oid list for all targets */
25857836SJohn.Forte@Sun.COM 		ll_info.ll_all_tgts = B_TRUE;
25867836SJohn.Forte@Sun.COM 	} else {
25877836SJohn.Forte@Sun.COM 		/* get lun oid list for single target */
25887836SJohn.Forte@Sun.COM 		ll_info.ll_all_tgts = B_FALSE;
25897836SJohn.Forte@Sun.COM 		ll_info.ll_tgt_oid = (uint32_t)targetOid->objectSequenceNumber;
25907836SJohn.Forte@Sun.COM 	}
25917836SJohn.Forte@Sun.COM 	ll_info.ll_in_cnt = 0;
25927836SJohn.Forte@Sun.COM 
25937836SJohn.Forte@Sun.COM 	/*
25947836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the number of target LUNs.
25957836SJohn.Forte@Sun.COM 	 */
25967836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, &ll_info) != 0) {
25977836SJohn.Forte@Sun.COM 		(void) close(fd);
25987836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
25997836SJohn.Forte@Sun.COM 		    "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno);
26007836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
26017836SJohn.Forte@Sun.COM 	}
26027836SJohn.Forte@Sun.COM 
26037836SJohn.Forte@Sun.COM 	lun_list_size = sizeof (iscsi_lun_list_t);
26047836SJohn.Forte@Sun.COM 	if (ll_info.ll_out_cnt > 1) {
26057836SJohn.Forte@Sun.COM 		lun_list_size += (sizeof (iscsi_if_lun_t) *
26067836SJohn.Forte@Sun.COM 		    (ll_info.ll_out_cnt - 1));
26077836SJohn.Forte@Sun.COM 	}
26087836SJohn.Forte@Sun.COM 
26097836SJohn.Forte@Sun.COM 	illp = (iscsi_lun_list_t *)calloc(1, lun_list_size);
26107836SJohn.Forte@Sun.COM 	if (illp == NULL) {
26117836SJohn.Forte@Sun.COM 		(void) close(fd);
26127836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
26137836SJohn.Forte@Sun.COM 	}
26147836SJohn.Forte@Sun.COM 	illp->ll_vers = ISCSI_INTERFACE_VERSION;
26157836SJohn.Forte@Sun.COM 	illp->ll_all_tgts = ll_info.ll_all_tgts;
26167836SJohn.Forte@Sun.COM 	illp->ll_tgt_oid = ll_info.ll_tgt_oid;
26177836SJohn.Forte@Sun.COM 	illp->ll_in_cnt = ll_info.ll_out_cnt;
26187836SJohn.Forte@Sun.COM 
26197836SJohn.Forte@Sun.COM 	/* Issue the same ioctl again to get the target LUN list */
26207836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) {
26217836SJohn.Forte@Sun.COM 		free(illp);
26227836SJohn.Forte@Sun.COM 		(void) close(fd);
26237836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
26247836SJohn.Forte@Sun.COM 		    "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno);
26257836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
26267836SJohn.Forte@Sun.COM 	}
26277836SJohn.Forte@Sun.COM 
26287836SJohn.Forte@Sun.COM 	*ppLunList = illp;
26297836SJohn.Forte@Sun.COM 
26307836SJohn.Forte@Sun.COM 	(void) close(fd);
26317836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
26327836SJohn.Forte@Sun.COM }
26337836SJohn.Forte@Sun.COM 
26347836SJohn.Forte@Sun.COM 
26357836SJohn.Forte@Sun.COM /* A helper function to set authentication method. */
26367836SJohn.Forte@Sun.COM static IMA_STATUS
setAuthMethods(IMA_OID oid,IMA_UINT * pMethodCount,const IMA_AUTHMETHOD * pMethodList)26377836SJohn.Forte@Sun.COM setAuthMethods(
26387836SJohn.Forte@Sun.COM     IMA_OID oid,
26397836SJohn.Forte@Sun.COM     IMA_UINT *pMethodCount,
26407836SJohn.Forte@Sun.COM     const IMA_AUTHMETHOD *pMethodList
26417836SJohn.Forte@Sun.COM )
26427836SJohn.Forte@Sun.COM {
26437836SJohn.Forte@Sun.COM 	int fd;
26447836SJohn.Forte@Sun.COM 	int i;
26457836SJohn.Forte@Sun.COM 	iscsi_auth_props_t auth;
26467836SJohn.Forte@Sun.COM 
26477836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
26487836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
26497836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
26507836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
26517836SJohn.Forte@Sun.COM 	}
26527836SJohn.Forte@Sun.COM 	(void) memset(&auth, 0, sizeof (iscsi_auth_props_t));
26537836SJohn.Forte@Sun.COM 	auth.a_vers = ISCSI_INTERFACE_VERSION;
26547836SJohn.Forte@Sun.COM 	auth.a_oid = (uint32_t)oid.objectSequenceNumber;
26557836SJohn.Forte@Sun.COM 	/* First do a get because other data fields may exist */
26567836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) {
26577836SJohn.Forte@Sun.COM 		/* EMPTY */
26587836SJohn.Forte@Sun.COM 		/* It is fine if there is no other data fields. */
26597836SJohn.Forte@Sun.COM 	}
26607836SJohn.Forte@Sun.COM 	auth.a_auth_method = authMethodNone;
26617836SJohn.Forte@Sun.COM 
26627836SJohn.Forte@Sun.COM 	for (i = 0; i < *pMethodCount; i++) {
26637836SJohn.Forte@Sun.COM 		switch (pMethodList[i]) {
26647836SJohn.Forte@Sun.COM 			case IMA_AUTHMETHOD_CHAP:
26657836SJohn.Forte@Sun.COM 				auth.a_auth_method |= authMethodCHAP;
26667836SJohn.Forte@Sun.COM 				break;
26677836SJohn.Forte@Sun.COM 			default:
26687836SJohn.Forte@Sun.COM 				break;
26697836SJohn.Forte@Sun.COM 		}
26707836SJohn.Forte@Sun.COM 	}
26717836SJohn.Forte@Sun.COM 
26727836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) {
26737836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
26747836SJohn.Forte@Sun.COM 		    "ISCSI_AUTH_SET failed, errno: %d", errno);
26757836SJohn.Forte@Sun.COM 		(void) close(fd);
26767836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
26777836SJohn.Forte@Sun.COM 	}
26787836SJohn.Forte@Sun.COM 
26797836SJohn.Forte@Sun.COM 	(void) close(fd);
26807836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
26817836SJohn.Forte@Sun.COM }
26827836SJohn.Forte@Sun.COM 
26837836SJohn.Forte@Sun.COM /* A helper function to get authentication method. */
26847836SJohn.Forte@Sun.COM static IMA_STATUS
getAuthMethods(IMA_OID oid,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)26857836SJohn.Forte@Sun.COM getAuthMethods(
26867836SJohn.Forte@Sun.COM     IMA_OID oid,
26877836SJohn.Forte@Sun.COM     IMA_UINT	*pMethodCount,
26887836SJohn.Forte@Sun.COM     IMA_AUTHMETHOD *pMethodList
26897836SJohn.Forte@Sun.COM )
26907836SJohn.Forte@Sun.COM {
26917836SJohn.Forte@Sun.COM 	int fd, i;
26927836SJohn.Forte@Sun.COM 	iscsi_auth_props_t auth;
26937836SJohn.Forte@Sun.COM 
26947836SJohn.Forte@Sun.COM 	if (pMethodList == NULL) {
26957836SJohn.Forte@Sun.COM 		*pMethodCount = 0;
26967836SJohn.Forte@Sun.COM 		return (IMA_STATUS_SUCCESS);
26977836SJohn.Forte@Sun.COM 	}
26987836SJohn.Forte@Sun.COM 
26997836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
27007836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
27017836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
27027836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
27037836SJohn.Forte@Sun.COM 	}
27047836SJohn.Forte@Sun.COM 
27057836SJohn.Forte@Sun.COM 	(void) memset(&auth, 0, sizeof (iscsi_auth_props_t));
27067836SJohn.Forte@Sun.COM 	auth.a_vers = ISCSI_INTERFACE_VERSION;
27077836SJohn.Forte@Sun.COM 	auth.a_oid = (uint32_t)oid.objectSequenceNumber;
27087836SJohn.Forte@Sun.COM 
27097836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) {
27107836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
27117836SJohn.Forte@Sun.COM 		    "ISCSI_AUTH_GET failed, errno: %d", errno);
27127836SJohn.Forte@Sun.COM 		(void) close(fd);
27137836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
27147836SJohn.Forte@Sun.COM 	}
27157836SJohn.Forte@Sun.COM 
27167836SJohn.Forte@Sun.COM 	i = 0;
27177836SJohn.Forte@Sun.COM 	if (auth.a_auth_method == IMA_AUTHMETHOD_NONE) {
27187836SJohn.Forte@Sun.COM 		pMethodList[i++] = IMA_AUTHMETHOD_NONE;
27197836SJohn.Forte@Sun.COM 	} else if (auth.a_auth_method & authMethodCHAP) {
27207836SJohn.Forte@Sun.COM 		pMethodList[i++] = IMA_AUTHMETHOD_CHAP;
27217836SJohn.Forte@Sun.COM 	}
27227836SJohn.Forte@Sun.COM 	*pMethodCount = i;
27237836SJohn.Forte@Sun.COM 
27247836SJohn.Forte@Sun.COM 	(void) close(fd);
27257836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
27267836SJohn.Forte@Sun.COM }
27277836SJohn.Forte@Sun.COM 
IMA_GetPhbaOidList(IMA_OID_LIST ** ppList)27287836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaOidList(
27297836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
27307836SJohn.Forte@Sun.COM )
27317836SJohn.Forte@Sun.COM {
27327836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST));
27337836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
27347836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
27357836SJohn.Forte@Sun.COM 	}
27367836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = 0;
27377836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
27387836SJohn.Forte@Sun.COM }
27397836SJohn.Forte@Sun.COM 
27407836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPhbaProperties(IMA_OID phbaOid,IMA_PHBA_PROPERTIES * pProps)27417836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaProperties(
27427836SJohn.Forte@Sun.COM 		IMA_OID phbaOid,
27437836SJohn.Forte@Sun.COM 		IMA_PHBA_PROPERTIES *pProps
27447836SJohn.Forte@Sun.COM )
27457836SJohn.Forte@Sun.COM {
27467836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
27477836SJohn.Forte@Sun.COM }
27487836SJohn.Forte@Sun.COM 
27497836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPhbaStatus(IMA_OID phbaOid,IMA_PHBA_STATUS * pStatus)27507836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaStatus(
27517836SJohn.Forte@Sun.COM 		IMA_OID phbaOid,
27527836SJohn.Forte@Sun.COM 		IMA_PHBA_STATUS *pStatus
27537836SJohn.Forte@Sun.COM )
27547836SJohn.Forte@Sun.COM {
27557836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
27567836SJohn.Forte@Sun.COM }
27577836SJohn.Forte@Sun.COM 
27587836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPhbaDownloadProperties(IMA_OID phbaOid,IMA_PHBA_DOWNLOAD_PROPERTIES * pProps)27597836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaDownloadProperties(
27607836SJohn.Forte@Sun.COM 		IMA_OID phbaOid,
27617836SJohn.Forte@Sun.COM 		IMA_PHBA_DOWNLOAD_PROPERTIES *pProps
27627836SJohn.Forte@Sun.COM )
27637836SJohn.Forte@Sun.COM {
27647836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
27657836SJohn.Forte@Sun.COM }
27667836SJohn.Forte@Sun.COM 
27677836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_IsPhbaDownloadFile(IMA_OID phbaOid,const IMA_WCHAR * pFileName,IMA_PHBA_DOWNLOAD_IMAGE_PROPERTIES * pProps)27687836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_IsPhbaDownloadFile(
27697836SJohn.Forte@Sun.COM 		IMA_OID phbaOid,
27707836SJohn.Forte@Sun.COM 		const IMA_WCHAR *pFileName,
27717836SJohn.Forte@Sun.COM 		IMA_PHBA_DOWNLOAD_IMAGE_PROPERTIES *pProps
27727836SJohn.Forte@Sun.COM )
27737836SJohn.Forte@Sun.COM {
27747836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
27757836SJohn.Forte@Sun.COM }
27767836SJohn.Forte@Sun.COM 
27777836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_PhbaDownload(IMA_OID phbaOid,IMA_PHBA_DOWNLOAD_IMAGE_TYPE imageType,const IMA_WCHAR * pFileName)27787836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_PhbaDownload(
27797836SJohn.Forte@Sun.COM 		IMA_OID phbaOid,
27807836SJohn.Forte@Sun.COM 		IMA_PHBA_DOWNLOAD_IMAGE_TYPE imageType,
27817836SJohn.Forte@Sun.COM 		const IMA_WCHAR *pFileName
27827836SJohn.Forte@Sun.COM )
27837836SJohn.Forte@Sun.COM {
27847836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
27857836SJohn.Forte@Sun.COM }
27867836SJohn.Forte@Sun.COM 
IMA_GetPnpOidList(IMA_OID pnpOid,IMA_OID_LIST ** ppList)27877836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpOidList(
27887836SJohn.Forte@Sun.COM 		IMA_OID pnpOid,
27897836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
27907836SJohn.Forte@Sun.COM )
27917836SJohn.Forte@Sun.COM {
27927836SJohn.Forte@Sun.COM 	/*
27937836SJohn.Forte@Sun.COM 	 * Always return the same object ID for the pnp as the spec
27947836SJohn.Forte@Sun.COM 	 * states that this function will always return a list of at least
27957836SJohn.Forte@Sun.COM 	 * one element
27967836SJohn.Forte@Sun.COM 	 */
27977836SJohn.Forte@Sun.COM 	pnpOid.objectType = IMA_OBJECT_TYPE_PNP;
27987836SJohn.Forte@Sun.COM 	pnpOid.ownerId = pluginOwnerId;
27997836SJohn.Forte@Sun.COM 	pnpOid.objectSequenceNumber = ISCSI_INITIATOR_OID;
28007836SJohn.Forte@Sun.COM 
28017836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
28027836SJohn.Forte@Sun.COM 	    (1* sizeof (IMA_OID)));
28037836SJohn.Forte@Sun.COM 
28047836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
28057836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
28067836SJohn.Forte@Sun.COM 	}
28077836SJohn.Forte@Sun.COM 
28087836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = 1;
28097836SJohn.Forte@Sun.COM 	(void) memcpy(&(*ppList)->oids[0], &pnpOid, sizeof (pnpOid));
28107836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
28117836SJohn.Forte@Sun.COM }
28127836SJohn.Forte@Sun.COM 
28137836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPnpProperties(IMA_OID pnpOid,IMA_PNP_PROPERTIES * pProps)28147836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpProperties(
28157836SJohn.Forte@Sun.COM 		IMA_OID pnpOid,
28167836SJohn.Forte@Sun.COM 		IMA_PNP_PROPERTIES *pProps
28177836SJohn.Forte@Sun.COM )
28187836SJohn.Forte@Sun.COM {
28197836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28207836SJohn.Forte@Sun.COM }
28217836SJohn.Forte@Sun.COM 
28227836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPnpStatistics(IMA_OID pnpOid,IMA_PNP_STATISTICS * pStats)28237836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpStatistics(
28247836SJohn.Forte@Sun.COM 		IMA_OID pnpOid,
28257836SJohn.Forte@Sun.COM 		IMA_PNP_STATISTICS *pStats
28267836SJohn.Forte@Sun.COM )
28277836SJohn.Forte@Sun.COM {
28287836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28297836SJohn.Forte@Sun.COM }
28307836SJohn.Forte@Sun.COM 
28317836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetIpProperties(IMA_OID oid,IMA_IP_PROPERTIES * pProps)28327836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetIpProperties(
28337836SJohn.Forte@Sun.COM 		IMA_OID oid,
28347836SJohn.Forte@Sun.COM 		IMA_IP_PROPERTIES *pProps
28357836SJohn.Forte@Sun.COM )
28367836SJohn.Forte@Sun.COM {
28377836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28387836SJohn.Forte@Sun.COM }
28397836SJohn.Forte@Sun.COM 
28407836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetDefaultGateway(IMA_OID oid,IMA_IP_ADDRESS defaultGateway)28417836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDefaultGateway(
28427836SJohn.Forte@Sun.COM 		IMA_OID oid,
28437836SJohn.Forte@Sun.COM 		IMA_IP_ADDRESS defaultGateway
28447836SJohn.Forte@Sun.COM )
28457836SJohn.Forte@Sun.COM {
28467836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28477836SJohn.Forte@Sun.COM }
28487836SJohn.Forte@Sun.COM 
28497836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetDnsServerAddress(IMA_OID oid,const IMA_IP_ADDRESS * pPrimaryDnsServerAddress,const IMA_IP_ADDRESS * pAlternateDnsServerAddress)28507836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDnsServerAddress(
28517836SJohn.Forte@Sun.COM 		IMA_OID oid,
28527836SJohn.Forte@Sun.COM 		const IMA_IP_ADDRESS *pPrimaryDnsServerAddress,
28537836SJohn.Forte@Sun.COM 		const IMA_IP_ADDRESS *pAlternateDnsServerAddress
28547836SJohn.Forte@Sun.COM )
28557836SJohn.Forte@Sun.COM {
28567836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28577836SJohn.Forte@Sun.COM }
28587836SJohn.Forte@Sun.COM 
28597836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetSubnetMask(IMA_OID oid,IMA_IP_ADDRESS subnetMask)28607836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetSubnetMask(
28617836SJohn.Forte@Sun.COM 		IMA_OID oid,
28627836SJohn.Forte@Sun.COM 		IMA_IP_ADDRESS subnetMask
28637836SJohn.Forte@Sun.COM )
28647836SJohn.Forte@Sun.COM {
28657836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28667836SJohn.Forte@Sun.COM }
28677836SJohn.Forte@Sun.COM 
28687836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetIpConfigMethod(IMA_OID oid,IMA_BOOL enableDhcpIpConfiguration)28697836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetIpConfigMethod(
28707836SJohn.Forte@Sun.COM 		IMA_OID oid,
28717836SJohn.Forte@Sun.COM 		IMA_BOOL enableDhcpIpConfiguration
28727836SJohn.Forte@Sun.COM )
28737836SJohn.Forte@Sun.COM {
28747836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
28757836SJohn.Forte@Sun.COM }
28767836SJohn.Forte@Sun.COM 
IMA_RegisterForObjectPropertyChanges(IMA_OBJECT_PROPERTY_FN pClientFn)28777836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RegisterForObjectPropertyChanges(
28787836SJohn.Forte@Sun.COM 		IMA_OBJECT_PROPERTY_FN pClientFn
28797836SJohn.Forte@Sun.COM )
28807836SJohn.Forte@Sun.COM {
28817836SJohn.Forte@Sun.COM 	pObjectPropertyCallback = pClientFn;
28827836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
28837836SJohn.Forte@Sun.COM }
28847836SJohn.Forte@Sun.COM 
28857836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_DeregisterForObjectPropertyChanges(IMA_OBJECT_PROPERTY_FN pClientFn)28867836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_DeregisterForObjectPropertyChanges(
28877836SJohn.Forte@Sun.COM 		IMA_OBJECT_PROPERTY_FN pClientFn
28887836SJohn.Forte@Sun.COM )
28897836SJohn.Forte@Sun.COM {
28907836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
28917836SJohn.Forte@Sun.COM }
28927836SJohn.Forte@Sun.COM 
IMA_RegisterForObjectVisibilityChanges(IMA_OBJECT_VISIBILITY_FN pClientFn)28937836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RegisterForObjectVisibilityChanges(
28947836SJohn.Forte@Sun.COM 		IMA_OBJECT_VISIBILITY_FN pClientFn
28957836SJohn.Forte@Sun.COM )
28967836SJohn.Forte@Sun.COM {
28977836SJohn.Forte@Sun.COM 	pObjectVisibilityCallback = pClientFn;
28987836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
28997836SJohn.Forte@Sun.COM }
29007836SJohn.Forte@Sun.COM 
29017836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_DeregisterForObjectVisibilityChanges(IMA_OBJECT_VISIBILITY_FN pClientFn)29027836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_DeregisterForObjectVisibilityChanges(
29037836SJohn.Forte@Sun.COM 		IMA_OBJECT_VISIBILITY_FN pClientFn
29047836SJohn.Forte@Sun.COM )
29057836SJohn.Forte@Sun.COM {
29067836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
29077836SJohn.Forte@Sun.COM }
29087836SJohn.Forte@Sun.COM 
29097836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetNetworkPortStatus(IMA_OID portOid,IMA_NETWORK_PORT_STATUS * pStaus)29107836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortStatus(
29117836SJohn.Forte@Sun.COM 		IMA_OID portOid,
29127836SJohn.Forte@Sun.COM 		IMA_NETWORK_PORT_STATUS *pStaus
29137836SJohn.Forte@Sun.COM )
29147836SJohn.Forte@Sun.COM {
29157836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
29167836SJohn.Forte@Sun.COM }
29177836SJohn.Forte@Sun.COM 
29187836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetNetworkPortalOidList(IMA_OID pnpOid,IMA_OID_LIST ** ppList)29197836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortalOidList(
29207836SJohn.Forte@Sun.COM 		IMA_OID pnpOid,
29217836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
29227836SJohn.Forte@Sun.COM )
29237836SJohn.Forte@Sun.COM {
29247836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
29257836SJohn.Forte@Sun.COM }
29267836SJohn.Forte@Sun.COM 
29277836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetNetworkPortalProperties(IMA_OID networkPortalOid,IMA_NETWORK_PORTAL_PROPERTIES * pProps)29287836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortalProperties(
29297836SJohn.Forte@Sun.COM 		IMA_OID networkPortalOid,
29307836SJohn.Forte@Sun.COM 		IMA_NETWORK_PORTAL_PROPERTIES *pProps
29317836SJohn.Forte@Sun.COM )
29327836SJohn.Forte@Sun.COM {
29337836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
29347836SJohn.Forte@Sun.COM }
29357836SJohn.Forte@Sun.COM 
29367836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_SetNetworkPortalIpAddress(IMA_OID networkPortalOid,const IMA_IP_ADDRESS NewIpAddress)29377836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNetworkPortalIpAddress(
29387836SJohn.Forte@Sun.COM 		IMA_OID networkPortalOid,
29397836SJohn.Forte@Sun.COM 		const IMA_IP_ADDRESS NewIpAddress
29407836SJohn.Forte@Sun.COM )
29417836SJohn.Forte@Sun.COM {
29427836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
29437836SJohn.Forte@Sun.COM }
29447836SJohn.Forte@Sun.COM 
29457836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_RemoveStaleData(IMA_OID lhbaOid)29467836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveStaleData(
29477836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid
29487836SJohn.Forte@Sun.COM )
29497836SJohn.Forte@Sun.COM {
29507836SJohn.Forte@Sun.COM 	return (IMA_ERROR_NOT_SUPPORTED);
29517836SJohn.Forte@Sun.COM }
29527836SJohn.Forte@Sun.COM 
29537836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetIpsecProperties(IMA_OID oid,IMA_IPSEC_PROPERTIES * pProps)29547836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetIpsecProperties(
29557836SJohn.Forte@Sun.COM 		IMA_OID oid,
29567836SJohn.Forte@Sun.COM 		IMA_IPSEC_PROPERTIES *pProps
29577836SJohn.Forte@Sun.COM )
29587836SJohn.Forte@Sun.COM {
29597836SJohn.Forte@Sun.COM 	pProps->ipsecSupported = IMA_TRUE;
29607836SJohn.Forte@Sun.COM 	pProps->implementedInHardware = IMA_FALSE;
29617836SJohn.Forte@Sun.COM 	pProps->implementedInSoftware = IMA_TRUE;
29627836SJohn.Forte@Sun.COM 
29637836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
29647836SJohn.Forte@Sun.COM }
29657836SJohn.Forte@Sun.COM 
29667836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetLhbaProperties(IMA_OID lhbaOid,IMA_LHBA_PROPERTIES * pProps)29677836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLhbaProperties(
29687836SJohn.Forte@Sun.COM 		IMA_OID lhbaOid,
29697836SJohn.Forte@Sun.COM 		IMA_LHBA_PROPERTIES *pProps
29707836SJohn.Forte@Sun.COM )
29717836SJohn.Forte@Sun.COM {
29727836SJohn.Forte@Sun.COM 
29737836SJohn.Forte@Sun.COM 	if (pProps == NULL) {
29747836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INVALID_PARAMETER);
29757836SJohn.Forte@Sun.COM 	}
29767836SJohn.Forte@Sun.COM 
29777836SJohn.Forte@Sun.COM 	if (lhbaObjectId.objectSequenceNumber != ISCSI_INITIATOR_OID) {
29787836SJohn.Forte@Sun.COM 		return (IMA_ERROR_OBJECT_NOT_FOUND);
29797836SJohn.Forte@Sun.COM 	}
29807836SJohn.Forte@Sun.COM 
29817836SJohn.Forte@Sun.COM 	(void) memset(pProps, 0, sizeof (IMA_LHBA_PROPERTIES));
29827836SJohn.Forte@Sun.COM 	(void) mbstowcs(pProps->osDeviceName, OS_DEVICE_NAME,
29837836SJohn.Forte@Sun.COM 	    OS_DEVICE_NAME_LEN);
29847836SJohn.Forte@Sun.COM 	pProps->luExposingSupported = IMA_FALSE;
29857836SJohn.Forte@Sun.COM 	pProps->isDestroyable = IMA_FALSE;
29867836SJohn.Forte@Sun.COM 	pProps->staleDataRemovable = IMA_FALSE;
29877836SJohn.Forte@Sun.COM 	pProps->staleDataSize = 0;
29887836SJohn.Forte@Sun.COM 	pProps->initiatorAuthMethodsSettable = IMA_TRUE;
29897836SJohn.Forte@Sun.COM 	pProps->targetAuthMethodsSettable = IMA_FALSE;
29907836SJohn.Forte@Sun.COM 
29917836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
29927836SJohn.Forte@Sun.COM }
29937836SJohn.Forte@Sun.COM 
IMA_GetLnpOidList(IMA_OID_LIST ** ppList)29947836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLnpOidList(
29957836SJohn.Forte@Sun.COM 		IMA_OID_LIST **ppList
29967836SJohn.Forte@Sun.COM )
29977836SJohn.Forte@Sun.COM {
29987836SJohn.Forte@Sun.COM 	*ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST)));
29997836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
30007836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
30017836SJohn.Forte@Sun.COM 	}
30027836SJohn.Forte@Sun.COM 	(*ppList)->oidCount = 0;
30037836SJohn.Forte@Sun.COM 
30047836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
30057836SJohn.Forte@Sun.COM }
30067836SJohn.Forte@Sun.COM 
30077836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetLnpProperties(IMA_OID lnpOid,IMA_LNP_PROPERTIES * pProps)30087836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLnpProperties(
30097836SJohn.Forte@Sun.COM 		IMA_OID lnpOid,
30107836SJohn.Forte@Sun.COM 		IMA_LNP_PROPERTIES *pProps
30117836SJohn.Forte@Sun.COM )
30127836SJohn.Forte@Sun.COM {
30137836SJohn.Forte@Sun.COM 	return (IMA_ERROR_OBJECT_NOT_FOUND);
30147836SJohn.Forte@Sun.COM }
30157836SJohn.Forte@Sun.COM 
30167836SJohn.Forte@Sun.COM #define	IMA_DISK_DEVICE_NAME_PREFIX	"/dev/rdsk/"
30177836SJohn.Forte@Sun.COM #define	IMA_TAPE_DEVICE_NAME_PREFIX	"/dev/rmt/"
30187836SJohn.Forte@Sun.COM static int
get_lun_devlink(di_devlink_t link,void * osDeviceName)30197836SJohn.Forte@Sun.COM get_lun_devlink(di_devlink_t link, void *osDeviceName)
30207836SJohn.Forte@Sun.COM {
30217836SJohn.Forte@Sun.COM 	if ((strncmp(IMA_DISK_DEVICE_NAME_PREFIX, di_devlink_path(link),
30227836SJohn.Forte@Sun.COM 	    strlen(IMA_DISK_DEVICE_NAME_PREFIX)) == 0) ||
30237836SJohn.Forte@Sun.COM 	    (strncmp(IMA_TAPE_DEVICE_NAME_PREFIX, di_devlink_path(link),
30247836SJohn.Forte@Sun.COM 	    strlen(IMA_TAPE_DEVICE_NAME_PREFIX)) == 0)) {
30257836SJohn.Forte@Sun.COM 		(void) mbstowcs((wchar_t *)osDeviceName, di_devlink_path(link),
30267836SJohn.Forte@Sun.COM 		    MAXPATHLEN);
30277836SJohn.Forte@Sun.COM 		return (DI_WALK_TERMINATE);
30287836SJohn.Forte@Sun.COM 	}
30297836SJohn.Forte@Sun.COM 
30307836SJohn.Forte@Sun.COM 	return (DI_WALK_CONTINUE);
30317836SJohn.Forte@Sun.COM }
30327836SJohn.Forte@Sun.COM 
30337836SJohn.Forte@Sun.COM /* ARGSUSED */
IMA_GetPluginProperties(IMA_OID pluginOid,IMA_PLUGIN_PROPERTIES * pProps)30347836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPluginProperties(
30357836SJohn.Forte@Sun.COM 	IMA_OID pluginOid,
30367836SJohn.Forte@Sun.COM 	IMA_PLUGIN_PROPERTIES *pProps
30377836SJohn.Forte@Sun.COM )
30387836SJohn.Forte@Sun.COM {
30397836SJohn.Forte@Sun.COM 	pProps->supportedImaVersion = 1;
30407836SJohn.Forte@Sun.COM 	libSwprintf(pProps->vendor, L"%ls", LIBRARY_PROPERTY_VENDOR);
30417836SJohn.Forte@Sun.COM 	libSwprintf(pProps->implementationVersion, L"%ls",
30427836SJohn.Forte@Sun.COM 	    LIBRARY_PROPERTY_IMPLEMENTATION_VERSION);
30437836SJohn.Forte@Sun.COM 	libSwprintf(pProps->fileName, L"%ls", LIBRARY_FILE_NAME);
30447836SJohn.Forte@Sun.COM 	GetBuildTime(&(pProps->buildTime));
30457836SJohn.Forte@Sun.COM 	pProps->lhbasCanBeCreatedAndDestroyed = IMA_FALSE;
30467836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
30477836SJohn.Forte@Sun.COM }
30487836SJohn.Forte@Sun.COM 
getDiscoveryAddressPropertiesList(SUN_IMA_DISC_ADDR_PROP_LIST ** ppList)30497836SJohn.Forte@Sun.COM IMA_STATUS getDiscoveryAddressPropertiesList(
30507836SJohn.Forte@Sun.COM     SUN_IMA_DISC_ADDR_PROP_LIST **ppList
30517836SJohn.Forte@Sun.COM )
30527836SJohn.Forte@Sun.COM {
30537836SJohn.Forte@Sun.COM 	int		    fd;
30547836SJohn.Forte@Sun.COM 	int		    i;
30557836SJohn.Forte@Sun.COM 	int		    discovery_addr_list_size;
30567836SJohn.Forte@Sun.COM 	iscsi_addr_list_t   *ialp, al_info;
30577836SJohn.Forte@Sun.COM 
30587836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
30597836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
30607836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
30617836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
30627836SJohn.Forte@Sun.COM 	}
30637836SJohn.Forte@Sun.COM 
30647836SJohn.Forte@Sun.COM 	(void) memset(&al_info, 0, sizeof (al_info));
30657836SJohn.Forte@Sun.COM 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
30667836SJohn.Forte@Sun.COM 	al_info.al_in_cnt = 0;
30677836SJohn.Forte@Sun.COM 
30687836SJohn.Forte@Sun.COM 	/*
30697836SJohn.Forte@Sun.COM 	 * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl to obtain the number of
30707836SJohn.Forte@Sun.COM 	 * discovery addresses.
30717836SJohn.Forte@Sun.COM 	 */
30727836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
30737836SJohn.Forte@Sun.COM 		(void) close(fd);
30747836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
30757836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d",
30767836SJohn.Forte@Sun.COM 		    errno);
30777836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
30787836SJohn.Forte@Sun.COM 	}
30797836SJohn.Forte@Sun.COM 
30807836SJohn.Forte@Sun.COM 	discovery_addr_list_size = sizeof (iscsi_addr_list_t);
30817836SJohn.Forte@Sun.COM 	if (al_info.al_out_cnt > 1) {
30827836SJohn.Forte@Sun.COM 		discovery_addr_list_size += (sizeof (iscsi_addr_t) *
30837836SJohn.Forte@Sun.COM 		    al_info.al_out_cnt - 1);
30847836SJohn.Forte@Sun.COM 	}
30857836SJohn.Forte@Sun.COM 
30867836SJohn.Forte@Sun.COM 	ialp = (iscsi_addr_list_t *)calloc(1, discovery_addr_list_size);
30877836SJohn.Forte@Sun.COM 	if (ialp == NULL) {
30887836SJohn.Forte@Sun.COM 		(void) close(fd);
30897836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
30907836SJohn.Forte@Sun.COM 	}
30917836SJohn.Forte@Sun.COM 	ialp->al_vers = ISCSI_INTERFACE_VERSION;
30927836SJohn.Forte@Sun.COM 	ialp->al_in_cnt = al_info.al_out_cnt;
30937836SJohn.Forte@Sun.COM 
30947836SJohn.Forte@Sun.COM 	/*
30957836SJohn.Forte@Sun.COM 	 * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl again to obtain the
30967836SJohn.Forte@Sun.COM 	 * discovery addresses.
30977836SJohn.Forte@Sun.COM 	 */
30987836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, ialp) != 0) {
30997836SJohn.Forte@Sun.COM 		free(ialp);
31007836SJohn.Forte@Sun.COM 		(void) close(fd);
31017836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
31027836SJohn.Forte@Sun.COM 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d",
31037836SJohn.Forte@Sun.COM 		    errno);
31047836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
31057836SJohn.Forte@Sun.COM 	}
31067836SJohn.Forte@Sun.COM 
31077836SJohn.Forte@Sun.COM 	*ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *)
31087836SJohn.Forte@Sun.COM 	    calloc(1, sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) +
31097836SJohn.Forte@Sun.COM 	    ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES));
31107836SJohn.Forte@Sun.COM 
31117836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
31127836SJohn.Forte@Sun.COM 		free(ialp);
31137836SJohn.Forte@Sun.COM 		(void) close(fd);
31147836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
31157836SJohn.Forte@Sun.COM 	}
31167836SJohn.Forte@Sun.COM 	(*ppList)->discAddrCount = ialp->al_out_cnt;
31177836SJohn.Forte@Sun.COM 
31187836SJohn.Forte@Sun.COM 	for (i = 0; i < ialp->al_out_cnt; i++) {
31197836SJohn.Forte@Sun.COM 		if (ialp->al_addrs[i].a_addr.i_insize ==
31207836SJohn.Forte@Sun.COM 		    sizeof (struct in_addr)) {
31217836SJohn.Forte@Sun.COM 			(*ppList)->props[i].discoveryAddress.hostnameIpAddress.
31227836SJohn.Forte@Sun.COM 			id.ipAddress.ipv4Address = IMA_TRUE;
31237836SJohn.Forte@Sun.COM 		} else if (ialp->al_addrs[i].a_addr.i_insize ==
31247836SJohn.Forte@Sun.COM 		    sizeof (struct in6_addr)) {
31257836SJohn.Forte@Sun.COM 			(*ppList)->props[i].discoveryAddress.
31267836SJohn.Forte@Sun.COM 			hostnameIpAddress.id.ipAddress.ipv4Address = IMA_FALSE;
31277836SJohn.Forte@Sun.COM 		} else {
31287836SJohn.Forte@Sun.COM 			/* Should not happen */
31297836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
31307836SJohn.Forte@Sun.COM 			"ISCSI_STATIC_GET returned bad address");
31317836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
31327836SJohn.Forte@Sun.COM 		}
31337836SJohn.Forte@Sun.COM 
31347836SJohn.Forte@Sun.COM 		bcopy(&ialp->al_addrs[i].a_addr.i_addr,	(*ppList)->props[i].
31357836SJohn.Forte@Sun.COM 		    discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
31367836SJohn.Forte@Sun.COM 		    sizeof ((*ppList)->props[i].discoveryAddress.
31377836SJohn.Forte@Sun.COM 		    hostnameIpAddress.id.ipAddress.ipAddress));
31387836SJohn.Forte@Sun.COM 
31397836SJohn.Forte@Sun.COM 		(*ppList)->props[i].discoveryAddress.portNumber =
31407836SJohn.Forte@Sun.COM 		    ialp->al_addrs[i].a_port;
31417836SJohn.Forte@Sun.COM 	}
31427836SJohn.Forte@Sun.COM 
31437836SJohn.Forte@Sun.COM 	free(ialp);
31447836SJohn.Forte@Sun.COM 	(void) close(fd);
31457836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
31467836SJohn.Forte@Sun.COM }
31477836SJohn.Forte@Sun.COM 
31487836SJohn.Forte@Sun.COM 
31497836SJohn.Forte@Sun.COM /* ARGSUSED */
sendTargets(IMA_TARGET_ADDRESS address,SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES ** ppList)31507836SJohn.Forte@Sun.COM IMA_STATUS sendTargets(
31517836SJohn.Forte@Sun.COM     IMA_TARGET_ADDRESS address,
31527836SJohn.Forte@Sun.COM     SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList
31537836SJohn.Forte@Sun.COM )
31547836SJohn.Forte@Sun.COM {
31557836SJohn.Forte@Sun.COM 	char	*colonPos;
31567836SJohn.Forte@Sun.COM 	char	discAddrStr[SUN_IMA_IP_ADDRESS_LEN];
31577836SJohn.Forte@Sun.COM 	int	fd;
31587836SJohn.Forte@Sun.COM 	int	ctr;
31597836SJohn.Forte@Sun.COM 	int	stl_sz;
31607836SJohn.Forte@Sun.COM 	iscsi_sendtgts_list_t	*stl_hdr = NULL;
31617836SJohn.Forte@Sun.COM 	IMA_BOOL		retry = IMA_TRUE;
31627836SJohn.Forte@Sun.COM 
31637836SJohn.Forte@Sun.COM #define	SENDTGTS_DEFAULT_NUM_TARGETS	10
31647836SJohn.Forte@Sun.COM 
31657836SJohn.Forte@Sun.COM 	stl_sz = sizeof (*stl_hdr) + ((SENDTGTS_DEFAULT_NUM_TARGETS - 1) *
31667836SJohn.Forte@Sun.COM 	    sizeof (iscsi_sendtgts_entry_t));
31677836SJohn.Forte@Sun.COM 	stl_hdr = (iscsi_sendtgts_list_t *)calloc(1, stl_sz);
31687836SJohn.Forte@Sun.COM 	if (stl_hdr == NULL) {
31697836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
31707836SJohn.Forte@Sun.COM 	}
31717836SJohn.Forte@Sun.COM 	stl_hdr->stl_entry.e_vers = ISCSI_INTERFACE_VERSION;
31727836SJohn.Forte@Sun.COM 	stl_hdr->stl_in_cnt = SENDTGTS_DEFAULT_NUM_TARGETS;
31737836SJohn.Forte@Sun.COM 
31747836SJohn.Forte@Sun.COM 	colonPos = strchr(discAddrStr, ':');
31757836SJohn.Forte@Sun.COM 	if (colonPos == NULL) {
31767836SJohn.Forte@Sun.COM 		/* IPv4 */
31777836SJohn.Forte@Sun.COM 		stl_hdr->stl_entry.e_insize = sizeof (struct in_addr);
31787836SJohn.Forte@Sun.COM 	} else {
31797836SJohn.Forte@Sun.COM 		/* IPv6 */
31807836SJohn.Forte@Sun.COM 		stl_hdr->stl_entry.e_insize = sizeof (struct in6_addr);
31817836SJohn.Forte@Sun.COM 	}
31827836SJohn.Forte@Sun.COM 
31837836SJohn.Forte@Sun.COM 
31847836SJohn.Forte@Sun.COM 	bcopy(address.hostnameIpAddress.id.ipAddress.ipAddress,
31857836SJohn.Forte@Sun.COM 	    &stl_hdr->stl_entry.e_u,
31867836SJohn.Forte@Sun.COM 	    sizeof (address.hostnameIpAddress.id.ipAddress.ipAddress));
31877836SJohn.Forte@Sun.COM 	stl_hdr->stl_entry.e_port = address.portNumber;
31887836SJohn.Forte@Sun.COM 
31897836SJohn.Forte@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
31907836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
31917836SJohn.Forte@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
31927836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
31937836SJohn.Forte@Sun.COM 	}
31947836SJohn.Forte@Sun.COM 
31957836SJohn.Forte@Sun.COM retry_sendtgts:
31967836SJohn.Forte@Sun.COM 	/*
31977836SJohn.Forte@Sun.COM 	 * Issue ioctl to obtain the SendTargets list
31987836SJohn.Forte@Sun.COM 	 */
31997836SJohn.Forte@Sun.COM 	if (ioctl(fd, ISCSI_SENDTGTS_GET, stl_hdr) != 0) {
32007836SJohn.Forte@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
32017836SJohn.Forte@Sun.COM 		    "ISCSI_SENDTGTS_GET ioctl failed, errno: %d", errno);
32027836SJohn.Forte@Sun.COM 		(void) close(fd);
32037836SJohn.Forte@Sun.COM 		free(stl_hdr);
32047836SJohn.Forte@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
32057836SJohn.Forte@Sun.COM 	}
32067836SJohn.Forte@Sun.COM 
32077836SJohn.Forte@Sun.COM 	/* check if all targets received */
32087836SJohn.Forte@Sun.COM 	if (stl_hdr->stl_in_cnt < stl_hdr->stl_out_cnt) {
32097836SJohn.Forte@Sun.COM 		if (retry == IMA_TRUE) {
32107836SJohn.Forte@Sun.COM 			stl_sz = sizeof (*stl_hdr) +
32117836SJohn.Forte@Sun.COM 			    ((stl_hdr->stl_out_cnt - 1) *
32127836SJohn.Forte@Sun.COM 			    sizeof (iscsi_sendtgts_entry_t));
32137836SJohn.Forte@Sun.COM 			stl_hdr = (iscsi_sendtgts_list_t *)
32147836SJohn.Forte@Sun.COM 			    realloc(stl_hdr, stl_sz);
32157836SJohn.Forte@Sun.COM 			if (stl_hdr == NULL) {
32167836SJohn.Forte@Sun.COM 				(void) close(fd);
32177836SJohn.Forte@Sun.COM 				return (IMA_ERROR_INSUFFICIENT_MEMORY);
32187836SJohn.Forte@Sun.COM 			}
32197836SJohn.Forte@Sun.COM 			stl_hdr->stl_in_cnt = stl_hdr->stl_out_cnt;
32207836SJohn.Forte@Sun.COM 			retry = IMA_FALSE;
32217836SJohn.Forte@Sun.COM 			goto retry_sendtgts;
32227836SJohn.Forte@Sun.COM 		} else {
32237836SJohn.Forte@Sun.COM 			/*
32247836SJohn.Forte@Sun.COM 			 * don't retry after 2 attempts.  The target list
32257836SJohn.Forte@Sun.COM 			 * shouldn't continue to growing. Justs continue
32267836SJohn.Forte@Sun.COM 			 * on and display what was found.
32277836SJohn.Forte@Sun.COM 			 */
32287836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
32297836SJohn.Forte@Sun.COM 			    "ISCSI_SENDTGTS_GET overflow: "
32307836SJohn.Forte@Sun.COM 			    "failed to obtain all targets");
32317836SJohn.Forte@Sun.COM 			stl_hdr->stl_out_cnt = stl_hdr->stl_in_cnt;
32327836SJohn.Forte@Sun.COM 		}
32337836SJohn.Forte@Sun.COM 	}
32347836SJohn.Forte@Sun.COM 
32357836SJohn.Forte@Sun.COM 	(void) close(fd);
32367836SJohn.Forte@Sun.COM 
32377836SJohn.Forte@Sun.COM 	/* allocate for caller return buffer */
32387836SJohn.Forte@Sun.COM 	*ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1,
32397836SJohn.Forte@Sun.COM 	    sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) +
32407836SJohn.Forte@Sun.COM 	    stl_hdr->stl_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY));
32417836SJohn.Forte@Sun.COM 	if (*ppList == NULL) {
32427836SJohn.Forte@Sun.COM 		free(stl_hdr);
32437836SJohn.Forte@Sun.COM 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
32447836SJohn.Forte@Sun.COM 	}
32457836SJohn.Forte@Sun.COM 
32467836SJohn.Forte@Sun.COM 	(*ppList)->keyCount = stl_hdr->stl_out_cnt;
32477836SJohn.Forte@Sun.COM 
32487836SJohn.Forte@Sun.COM 	for (ctr = 0; ctr < stl_hdr->stl_out_cnt; ctr++) {
32497836SJohn.Forte@Sun.COM 		(void) mbstowcs((*ppList)->keys[ctr].name,
32507836SJohn.Forte@Sun.COM 		    (char *)stl_hdr->stl_list[ctr].ste_name,
32517836SJohn.Forte@Sun.COM 		    IMA_NODE_NAME_LEN);
32527836SJohn.Forte@Sun.COM 
32537836SJohn.Forte@Sun.COM 		(*ppList)->keys[ctr].tpgt = stl_hdr->stl_list[ctr].ste_tpgt;
32547836SJohn.Forte@Sun.COM 
32557836SJohn.Forte@Sun.COM 		(*ppList)->keys[ctr].address.portNumber =
32567836SJohn.Forte@Sun.COM 		    stl_hdr->stl_list[ctr].ste_ipaddr.a_port;
32577836SJohn.Forte@Sun.COM 
32587836SJohn.Forte@Sun.COM 		if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize ==
32597836SJohn.Forte@Sun.COM 		    sizeof (struct in_addr)) {
32607836SJohn.Forte@Sun.COM 			(*ppList)->keys[ctr].address.ipAddress.ipv4Address =
32617836SJohn.Forte@Sun.COM 			    IMA_TRUE;
32627836SJohn.Forte@Sun.COM 		} else if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize ==
32637836SJohn.Forte@Sun.COM 		    sizeof (struct in6_addr)) {
32647836SJohn.Forte@Sun.COM 			(*ppList)->keys[ctr].address.ipAddress.ipv4Address =
32657836SJohn.Forte@Sun.COM 			    IMA_FALSE;
32667836SJohn.Forte@Sun.COM 		} else {
32677836SJohn.Forte@Sun.COM 			free(stl_hdr);
32687836SJohn.Forte@Sun.COM 			syslog(LOG_USER|LOG_DEBUG,
32697836SJohn.Forte@Sun.COM 			"ISCSI_STATIC_GET returned bad address");
32707836SJohn.Forte@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
32717836SJohn.Forte@Sun.COM 		}
32727836SJohn.Forte@Sun.COM 
32737836SJohn.Forte@Sun.COM 
32747836SJohn.Forte@Sun.COM 		(void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress,
32757836SJohn.Forte@Sun.COM 		    &(stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_addr),
32767836SJohn.Forte@Sun.COM 		    stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize);
32777836SJohn.Forte@Sun.COM 	}
32787836SJohn.Forte@Sun.COM 	free(stl_hdr);
32797836SJohn.Forte@Sun.COM 
32807836SJohn.Forte@Sun.COM 	return (IMA_STATUS_SUCCESS);
32817836SJohn.Forte@Sun.COM }
328210156SZhang.Yi@Sun.COM 
SUN_IMA_GetTunableProperties(IMA_OID oid,ISCSI_TUNABLE_PARAM * param)328310156SZhang.Yi@Sun.COM IMA_API IMA_STATUS SUN_IMA_GetTunableProperties(
328410156SZhang.Yi@Sun.COM 	IMA_OID oid,
328510156SZhang.Yi@Sun.COM 	ISCSI_TUNABLE_PARAM *param)
328610156SZhang.Yi@Sun.COM {
328710156SZhang.Yi@Sun.COM 	int fd;
328810156SZhang.Yi@Sun.COM 	iscsi_tunable_object_t pg;
328910156SZhang.Yi@Sun.COM 
329010156SZhang.Yi@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
329110156SZhang.Yi@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
329210156SZhang.Yi@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
329310156SZhang.Yi@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
329410156SZhang.Yi@Sun.COM 	}
329510156SZhang.Yi@Sun.COM 	(void) memset(&pg, 0, sizeof (iscsi_tunable_object_t));
329610156SZhang.Yi@Sun.COM 	pg.t_param = param->tunable_objectType;
329710156SZhang.Yi@Sun.COM 	pg.t_oid = (uint32_t)oid.objectSequenceNumber;
329810156SZhang.Yi@Sun.COM 	if (ioctl(fd, ISCSI_TUNABLE_PARAM_GET, &pg) == -1) {
329910156SZhang.Yi@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
330010156SZhang.Yi@Sun.COM 		    "ISCSI_TUNABLE_PARAM_GET ioctl failed, errno: %d", errno);
330110156SZhang.Yi@Sun.COM 		(void) close(fd);
330210156SZhang.Yi@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
330310156SZhang.Yi@Sun.COM 	} else {
330410156SZhang.Yi@Sun.COM 		long long value;
330510156SZhang.Yi@Sun.COM 		char tmp[MAX_LONG_LONG_STRING_LEN], *ptr = NULL;
330610156SZhang.Yi@Sun.COM 		if (pg.t_set == B_FALSE) {
330710156SZhang.Yi@Sun.COM 			/* default value */
330810156SZhang.Yi@Sun.COM 			(void) close(fd);
330910156SZhang.Yi@Sun.COM 			return (IMA_STATUS_SUCCESS);
331010156SZhang.Yi@Sun.COM 		}
331110156SZhang.Yi@Sun.COM 		value = (long long)pg.t_value.v_integer;
3312*11275SZhang.Yi@Sun.COM 		ptr = lltostr(value, &tmp[MAX_LONG_LONG_STRING_LEN -1]);
331310156SZhang.Yi@Sun.COM 		if ((ptr != NULL) && (ptr != tmp)) {
3314*11275SZhang.Yi@Sun.COM 			tmp[MAX_LONG_LONG_STRING_LEN - 1] = '\0';
331510156SZhang.Yi@Sun.COM 		} else {
331610156SZhang.Yi@Sun.COM 			(void) close(fd);
331710156SZhang.Yi@Sun.COM 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
331810156SZhang.Yi@Sun.COM 		}
331910156SZhang.Yi@Sun.COM 		switch (param->tunable_objectType) {
332010156SZhang.Yi@Sun.COM 			case ISCSI_RX_TIMEOUT_VALUE:
332110156SZhang.Yi@Sun.COM 				(void) strlcpy(param->tunable_objectValue,
3322*11275SZhang.Yi@Sun.COM 				    ptr, strlen(ptr) + 1);
332310156SZhang.Yi@Sun.COM 				break;
332410156SZhang.Yi@Sun.COM 			case ISCSI_CONN_DEFAULT_LOGIN_MAX:
332510156SZhang.Yi@Sun.COM 				(void) strlcpy(param->tunable_objectValue,
3326*11275SZhang.Yi@Sun.COM 				    ptr, strlen(ptr) + 1);
332710156SZhang.Yi@Sun.COM 				break;
332810156SZhang.Yi@Sun.COM 			case ISCSI_LOGIN_POLLING_DELAY:
332910156SZhang.Yi@Sun.COM 				(void) strlcpy(param->tunable_objectValue,
3330*11275SZhang.Yi@Sun.COM 				    ptr, strlen(ptr) + 1);
333110156SZhang.Yi@Sun.COM 				break;
333210156SZhang.Yi@Sun.COM 			default:
333310156SZhang.Yi@Sun.COM 				break;
333410156SZhang.Yi@Sun.COM 		}
333510156SZhang.Yi@Sun.COM 	}
333610156SZhang.Yi@Sun.COM 	(void) close(fd);
333710156SZhang.Yi@Sun.COM 	return (IMA_STATUS_SUCCESS);
333810156SZhang.Yi@Sun.COM }
333910156SZhang.Yi@Sun.COM 
SUN_IMA_SetTunableProperties(IMA_OID oid,ISCSI_TUNABLE_PARAM * param)334010156SZhang.Yi@Sun.COM IMA_API IMA_STATUS SUN_IMA_SetTunableProperties(
334110156SZhang.Yi@Sun.COM 	IMA_OID oid,
334210156SZhang.Yi@Sun.COM 	ISCSI_TUNABLE_PARAM *param)
334310156SZhang.Yi@Sun.COM {
334410156SZhang.Yi@Sun.COM 	int fd;
334510156SZhang.Yi@Sun.COM 	iscsi_tunable_object_t	ps;
334610156SZhang.Yi@Sun.COM 
334710156SZhang.Yi@Sun.COM 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
334810156SZhang.Yi@Sun.COM 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
334910156SZhang.Yi@Sun.COM 		    ISCSI_DRIVER_DEVCTL, errno);
335010156SZhang.Yi@Sun.COM 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
335110156SZhang.Yi@Sun.COM 	}
335210156SZhang.Yi@Sun.COM 
335310156SZhang.Yi@Sun.COM 	(void) memset(&ps, 0, sizeof (iscsi_tunable_object_t));
335410156SZhang.Yi@Sun.COM 	ps.t_oid = oid.objectSequenceNumber;
335510156SZhang.Yi@Sun.COM 	ps.t_param = param->tunable_objectType;
335610156SZhang.Yi@Sun.COM 	switch (param->tunable_objectType) {
335710156SZhang.Yi@Sun.COM 		long tmp;
335810156SZhang.Yi@Sun.COM 		case ISCSI_RX_TIMEOUT_VALUE:
335910156SZhang.Yi@Sun.COM 		case ISCSI_CONN_DEFAULT_LOGIN_MAX:
336010156SZhang.Yi@Sun.COM 		case ISCSI_LOGIN_POLLING_DELAY:
336110156SZhang.Yi@Sun.COM 			tmp = strtol(param->tunable_objectValue,
336210156SZhang.Yi@Sun.COM 			    NULL, 10);
336310156SZhang.Yi@Sun.COM 			if (((tmp == 0) && (errno == EINVAL)) ||
336410156SZhang.Yi@Sun.COM 			    ((tmp == LONG_MAX) && (errno == ERANGE)) ||
336510156SZhang.Yi@Sun.COM 			    ((tmp == LONG_MIN) && (errno == ERANGE))) {
336610156SZhang.Yi@Sun.COM 				(void) close(fd);
336710156SZhang.Yi@Sun.COM 				return (IMA_ERROR_INVALID_PARAMETER);
336810156SZhang.Yi@Sun.COM 			}
336910156SZhang.Yi@Sun.COM 			ps.t_value.v_integer = (uint32_t)tmp;
337010156SZhang.Yi@Sun.COM 			break;
337110156SZhang.Yi@Sun.COM 		default:
337210156SZhang.Yi@Sun.COM 			break;
337310156SZhang.Yi@Sun.COM 	}
337410156SZhang.Yi@Sun.COM 	if (ioctl(fd, ISCSI_TUNABLE_PARAM_SET, &ps)) {
337510156SZhang.Yi@Sun.COM 		int tmpErrno = errno;
337610156SZhang.Yi@Sun.COM 		syslog(LOG_USER|LOG_DEBUG,
337710156SZhang.Yi@Sun.COM 		    "ISCSI_TUNABLE_PARAM_SET ioctl failed, errno: %d", errno);
337810156SZhang.Yi@Sun.COM 		(void) close(fd);
337910156SZhang.Yi@Sun.COM 		switch (tmpErrno) {
338010156SZhang.Yi@Sun.COM 			case ENOTSUP :
338110156SZhang.Yi@Sun.COM 				return (IMA_ERROR_NOT_SUPPORTED);
338210156SZhang.Yi@Sun.COM 			default:
338310156SZhang.Yi@Sun.COM 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
338410156SZhang.Yi@Sun.COM 		}
338510156SZhang.Yi@Sun.COM 	}
338610156SZhang.Yi@Sun.COM 	(void) close(fd);
338710156SZhang.Yi@Sun.COM 	return (IMA_STATUS_SUCCESS);
338810156SZhang.Yi@Sun.COM }
3389