summaryrefslogtreecommitdiff
path: root/usr/src/cmd/hotplugd/hotplugd_door.c
blob: 28fd69f86478a9150403faaceb336d30430871a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <strings.h>
#include <alloca.h>
#include <door.h>
#include <pthread.h>
#include <synch.h>
#include <pwd.h>
#include <auth_list.h>
#include <auth_attr.h>
#include <bsm/adt.h>
#include <bsm/adt_event.h>
#include <sys/sunddi.h>
#include <sys/ddi_hp.h>
#include <libnvpair.h>
#include <libhotplug.h>
#include <libhotplug_impl.h>
#include "hotplugd_impl.h"

/*
 * Buffer management for results.
 */
typedef struct i_buffer {
	uint64_t	seqnum;
	char		*buffer;
	struct i_buffer	*next;
} i_buffer_t;

static uint64_t		buffer_seqnum = 1;
static i_buffer_t	*buffer_list = NULL;
static pthread_mutex_t	buffer_lock = PTHREAD_MUTEX_INITIALIZER;

/*
 * Door file descriptor.
 */
static int	door_fd = -1;

/*
 * Function prototypes.
 */
static void	door_server(void *, char *, size_t, door_desc_t *, uint_t);
static int	check_auth(ucred_t *, const char *);
static int	cmd_getinfo(nvlist_t *, nvlist_t **);
static int	cmd_changestate(nvlist_t *, nvlist_t **);
static int	cmd_private(hp_cmd_t, nvlist_t *, nvlist_t **);
static void	add_buffer(uint64_t, char *);
static void	free_buffer(uint64_t);
static uint64_t	get_seqnum(void);
static char	*state_str(int);
static int	audit_session(ucred_t *, adt_session_data_t **);
static void	audit_changestate(ucred_t *, char *, char *, char *, int, int,
		    int);
static void	audit_setprivate(ucred_t *, char *, char *, char *, char *,
		    int);

/*
 * door_server_init()
 *
 *	Create the door file, and initialize the door server.
 */
boolean_t
door_server_init(void)
{
	int	fd;

	/* Create the door file */
	if ((fd = open(HOTPLUGD_DOOR, O_CREAT|O_EXCL|O_RDONLY, 0644)) == -1) {
		if (errno == EEXIST) {
			log_err("Door service is already running.\n");
		} else {
			log_err("Cannot open door file '%s': %s\n",
			    HOTPLUGD_DOOR, strerror(errno));
		}
		return (B_FALSE);
	}
	(void) close(fd);

	/* Initialize the door service */
	if ((door_fd = door_create(door_server, NULL,
	    DOOR_REFUSE_DESC | DOOR_NO_CANCEL)) == -1) {
		log_err("Cannot create door service: %s\n", strerror(errno));
		return (B_FALSE);
	}

	/* Cleanup stale door associations */
	(void) fdetach(HOTPLUGD_DOOR);

	/* Associate door service with door file */
	if (fattach(door_fd, HOTPLUGD_DOOR) != 0) {
		log_err("Cannot attach to door file '%s': %s\n", HOTPLUGD_DOOR,
		    strerror(errno));
		(void) door_revoke(door_fd);
		(void) fdetach(HOTPLUGD_DOOR);
		door_fd = -1;
		return (B_FALSE);
	}

	return (B_TRUE);
}

/*
 * door_server_fini()
 *
 *	Terminate and cleanup the door server.
 */
void
door_server_fini(void)
{
	if (door_fd != -1) {
		(void) door_revoke(door_fd);
		(void) fdetach(HOTPLUGD_DOOR);
	}

	(void) unlink(HOTPLUGD_DOOR);
}

/*
 * door_server()
 *
 *	This routine is the handler which responds to each door call.
 *	Each incoming door call is expected to send a packed nvlist
 *	of arguments which describe the requested action.  And each
 *	response is sent back as a packed nvlist of results.
 *
 *	Results are always allocated on the heap.  A global list of
 *	allocated result buffers is managed, and each one is tracked
 *	by a unique sequence number.  The final step in the protocol
 *	is for the caller to send a short response using the sequence
 *	number when the buffer can be released.
 */
/*ARGSUSED*/
static void
door_server(void *cookie, char *argp, size_t sz, door_desc_t *dp, uint_t ndesc)
{
	nvlist_t	*args = NULL;
	nvlist_t	*results = NULL;
	hp_cmd_t	cmd;
	int		rv;

	dprintf("Door call: cookie=%p, argp=%p, sz=%d\n", cookie, (void *)argp,
	    sz);

	/* Special case to free a results buffer */
	if (sz == sizeof (uint64_t)) {
		free_buffer(*(uint64_t *)(uintptr_t)argp);
		(void) door_return(NULL, 0, NULL, 0);
		return;
	}

	/* Unpack the arguments nvlist */
	if (nvlist_unpack(argp, sz, &args, 0) != 0) {
		log_err("Cannot unpack door arguments.\n");
		rv = EINVAL;
		goto fail;
	}

	/* Extract the requested command */
	if (nvlist_lookup_int32(args, HPD_CMD, (int32_t *)&cmd) != 0) {
		log_err("Cannot decode door command.\n");
		rv = EINVAL;
		goto fail;
	}

	/* Implement the command */
	switch (cmd) {
	case HP_CMD_GETINFO:
		rv = cmd_getinfo(args, &results);
		break;
	case HP_CMD_CHANGESTATE:
		rv = cmd_changestate(args, &results);
		break;
	case HP_CMD_SETPRIVATE:
	case HP_CMD_GETPRIVATE:
		rv = cmd_private(cmd, args, &results);
		break;
	default:
		rv = EINVAL;
		break;
	}

	/* The arguments nvlist is no longer needed */
	nvlist_free(args);
	args = NULL;

	/*
	 * If an nvlist was constructed for the results,
	 * then pack the results nvlist and return it.
	 */
	if (results != NULL) {
		uint64_t	seqnum;
		char		*buf = NULL;
		size_t		len = 0;

		/* Add a sequence number to the results */
		seqnum = get_seqnum();
		if (nvlist_add_uint64(results, HPD_SEQNUM, seqnum) != 0) {
			log_err("Cannot add sequence number.\n");
			rv = EFAULT;
			goto fail;
		}

		/* Pack the results nvlist */
		if (nvlist_pack(results, &buf, &len,
		    NV_ENCODE_NATIVE, 0) != 0) {
			log_err("Cannot pack door results.\n");
			rv = EFAULT;
			goto fail;
		}

		/* Link results buffer into list */
		add_buffer(seqnum, buf);

		/* The results nvlist is no longer needed */
		nvlist_free(results);

		/* Return the results */
		(void) door_return(buf, len, NULL, 0);
		return;
	}

	/* Return result code (when no nvlist) */
	(void) door_return((char *)&rv, sizeof (int), NULL, 0);
	return;

fail:
	log_err("Door call failed (%s)\n", strerror(rv));
	nvlist_free(args);
	nvlist_free(results);
	(void) door_return((char *)&rv, sizeof (int), NULL, 0);
}

/*
 * check_auth()
 *
 *	Perform an RBAC authorization check.
 */
static int
check_auth(ucred_t *ucred, const char *auth)
{
	struct passwd	pwd;
	uid_t		euid;
	char		buf[MAXPATHLEN];

	euid = ucred_geteuid(ucred);

	if ((getpwuid_r(euid, &pwd, buf, sizeof (buf)) == NULL) ||
	    (chkauthattr(auth, pwd.pw_name) == 0)) {
		log_info("Unauthorized door call.\n");
		return (-1);
	}

	return (0);
}

/*
 * cmd_getinfo()
 *
 *	Implements the door command to get a hotplug information snapshot.
 */
static int
cmd_getinfo(nvlist_t *args, nvlist_t **resultsp)
{
	hp_node_t	root;
	nvlist_t	*results;
	char		*path;
	char		*connection;
	char		*buf = NULL;
	size_t		len = 0;
	uint_t		flags;
	int		rv;

	dprintf("cmd_getinfo:\n");

	/* Get arguments */
	if (nvlist_lookup_string(args, HPD_PATH, &path) != 0) {
		dprintf("cmd_getinfo: invalid arguments.\n");
		return (EINVAL);
	}
	if (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0)
		connection = NULL;
	if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
		flags = 0;

	/* Get and pack the requested snapshot */
	if ((rv = getinfo(path, connection, flags, &root)) == 0) {
		rv = hp_pack(root, &buf, &len);
		hp_fini(root);
	}
	dprintf("cmd_getinfo: getinfo(): rv = %d, buf = %p.\n", rv,
	    (void *)buf);

	/*
	 * If the above failed or there is no snapshot,
	 * then only return a status code.
	 */
	if (rv != 0)
		return (rv);
	if (buf == NULL)
		return (EFAULT);

	/* Allocate nvlist for results */
	if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
		dprintf("cmd_getinfo: nvlist_alloc() failed.\n");
		free(buf);
		return (ENOMEM);
	}

	/* Add snapshot and successful status to results */
	if ((nvlist_add_int32(results, HPD_STATUS, 0) != 0) ||
	    (nvlist_add_byte_array(results, HPD_INFO,
	    (uchar_t *)buf, len) != 0)) {
		dprintf("cmd_getinfo: nvlist add failure.\n");
		nvlist_free(results);
		free(buf);
		return (ENOMEM);
	}

	/* Packed snapshot no longer needed */
	free(buf);

	/* Success */
	*resultsp = results;
	return (0);
}

/*
 * cmd_changestate()
 *
 *	Implements the door command to initate a state change operation.
 *
 *	NOTE: requires 'modify' authorization.
 */
static int
cmd_changestate(nvlist_t *args, nvlist_t **resultsp)
{
	hp_node_t	root = NULL;
	nvlist_t	*results = NULL;
	char		*path, *connection;
	ucred_t		*uc = NULL;
	uint_t		flags;
	int		rv, state, old_state, status;

	dprintf("cmd_changestate:\n");

	/* Get arguments */
	if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
	    (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
	    (nvlist_lookup_int32(args, HPD_STATE, &state) != 0)) {
		dprintf("cmd_changestate: invalid arguments.\n");
		return (EINVAL);
	}
	if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
		flags = 0;

	/* Get caller's credentials */
	if (door_ucred(&uc) != 0) {
		log_err("Cannot get door credentials (%s)\n", strerror(errno));
		return (EACCES);
	}

	/* Check authorization */
	if (check_auth(uc, HP_MODIFY_AUTH) != 0) {
		dprintf("cmd_changestate: access denied.\n");
		audit_changestate(uc, HP_MODIFY_AUTH, path, connection,
		    state, -1, ADT_FAIL_VALUE_AUTH);
		ucred_free(uc);
		return (EACCES);
	}

	/* Perform the state change operation */
	status = changestate(path, connection, state, flags, &old_state, &root);
	dprintf("cmd_changestate: changestate() == %d\n", status);

	/* Audit the operation */
	audit_changestate(uc, HP_MODIFY_AUTH, path, connection, state,
	    old_state, status);

	/* Caller's credentials no longer needed */
	ucred_free(uc);

	/*
	 * Pack the results into an nvlist if there is an error snapshot.
	 *
	 * If any error occurs while packing the results, the original
	 * error code from changestate() above is still returned.
	 */
	if (root != NULL) {
		char	*buf = NULL;
		size_t	len = 0;

		dprintf("cmd_changestate: results nvlist required.\n");

		/* Pack and discard the error snapshot */
		rv = hp_pack(root, &buf, &len);
		hp_fini(root);
		if (rv != 0) {
			dprintf("cmd_changestate: hp_pack() failed (%s).\n",
			    strerror(rv));
			return (status);
		}

		/* Allocate nvlist for results */
		if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
			dprintf("cmd_changestate: nvlist_alloc() failed.\n");
			free(buf);
			return (status);
		}

		/* Add the results into the nvlist */
		if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
		    (nvlist_add_byte_array(results, HPD_INFO, (uchar_t *)buf,
		    len) != 0)) {
			dprintf("cmd_changestate: nvlist add failed.\n");
			nvlist_free(results);
			free(buf);
			return (status);
		}

		*resultsp = results;
	}

	return (status);
}

/*
 * cmd_private()
 *
 *	Implementation of the door command to set or get bus private options.
 *
 *	NOTE: requires 'modify' authorization for the 'set' command.
 */
static int
cmd_private(hp_cmd_t cmd, nvlist_t *args, nvlist_t **resultsp)
{
	nvlist_t	*results = NULL;
	ucred_t		*uc = NULL;
	char		*path, *connection, *options;
	char		*values = NULL;
	int		status;

	dprintf("cmd_private:\n");

	/* Get caller's credentials */
	if ((cmd == HP_CMD_SETPRIVATE) && (door_ucred(&uc) != 0)) {
		log_err("Cannot get door credentials (%s)\n", strerror(errno));
		return (EACCES);
	}

	/* Get arguments */
	if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
	    (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
	    (nvlist_lookup_string(args, HPD_OPTIONS, &options) != 0)) {
		dprintf("cmd_private: invalid arguments.\n");
		return (EINVAL);
	}

	/* Check authorization */
	if ((cmd == HP_CMD_SETPRIVATE) &&
	    (check_auth(uc, HP_MODIFY_AUTH) != 0)) {
		dprintf("cmd_private: access denied.\n");
		audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
		    ADT_FAIL_VALUE_AUTH);
		ucred_free(uc);
		return (EACCES);
	}

	/* Perform the operation */
	status = private_options(path, connection, cmd, options, &values);
	dprintf("cmd_private: private_options() == %d\n", status);

	/* Audit the operation */
	if (cmd == HP_CMD_SETPRIVATE) {
		audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
		    status);
		ucred_free(uc);
	}

	/* Construct an nvlist if values were returned */
	if (values != NULL) {

		/* Allocate nvlist for results */
		if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
			dprintf("cmd_private: nvlist_alloc() failed.\n");
			free(values);
			return (ENOMEM);
		}

		/* Add values and status to the results */
		if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
		    (nvlist_add_string(results, HPD_OPTIONS, values) != 0)) {
			dprintf("cmd_private: nvlist add failed.\n");
			nvlist_free(results);
			free(values);
			return (ENOMEM);
		}

		/* The values string is no longer needed */
		free(values);

		*resultsp = results;
	}

	return (status);
}

/*
 * get_seqnum()
 *
 *	Allocate the next unique sequence number for a results buffer.
 */
static uint64_t
get_seqnum(void)
{
	uint64_t seqnum;

	(void) pthread_mutex_lock(&buffer_lock);

	seqnum = buffer_seqnum++;

	(void) pthread_mutex_unlock(&buffer_lock);

	return (seqnum);
}

/*
 * add_buffer()
 *
 *	Link a results buffer into the list containing all buffers.
 */
static void
add_buffer(uint64_t seqnum, char *buf)
{
	i_buffer_t	*node;

	if ((node = (i_buffer_t *)malloc(sizeof (i_buffer_t))) == NULL) {
		/* The consequence is a memory leak. */
		log_err("Cannot allocate results buffer: %s\n",
		    strerror(errno));
		return;
	}

	node->seqnum = seqnum;
	node->buffer = buf;

	(void) pthread_mutex_lock(&buffer_lock);

	node->next = buffer_list;
	buffer_list = node;

	(void) pthread_mutex_unlock(&buffer_lock);
}

/*
 * free_buffer()
 *
 *	Remove a results buffer from the list containing all buffers.
 */
static void
free_buffer(uint64_t seqnum)
{
	i_buffer_t	*node, *prev;

	(void) pthread_mutex_lock(&buffer_lock);

	prev = NULL;
	node = buffer_list;

	while (node) {
		if (node->seqnum == seqnum) {
			dprintf("Free buffer %lld\n", seqnum);
			if (prev) {
				prev->next = node->next;
			} else {
				buffer_list = node->next;
			}
			free(node->buffer);
			free(node);
			break;
		}
		prev = node;
		node = node->next;
	}

	(void) pthread_mutex_unlock(&buffer_lock);
}

/*
 * audit_session()
 *
 *	Initialize an audit session.
 */
static int
audit_session(ucred_t *ucred, adt_session_data_t **sessionp)
{
	adt_session_data_t	*session;

	if (adt_start_session(&session, NULL, 0) != 0) {
		log_err("Cannot start audit session.\n");
		return (-1);
	}

	if (adt_set_from_ucred(session, ucred, ADT_NEW) != 0) {
		log_err("Cannot set audit session from ucred.\n");
		(void) adt_end_session(session);
		return (-1);
	}

	*sessionp = session;
	return (0);
}

/*
 * audit_changestate()
 *
 *	Audit a 'changestate' door command.
 */
static void
audit_changestate(ucred_t *ucred, char *auth, char *path, char *connection,
    int new_state, int old_state, int result)
{
	adt_session_data_t	*session;
	adt_event_data_t	*event;
	int			pass_fail, fail_reason;

	if (audit_session(ucred, &session) != 0)
		return;

	if ((event = adt_alloc_event(session, ADT_hotplug_state)) == NULL) {
		(void) adt_end_session(session);
		return;
	}

	if (result == 0) {
		pass_fail = ADT_SUCCESS;
		fail_reason = ADT_SUCCESS;
	} else {
		pass_fail = ADT_FAILURE;
		fail_reason = result;
	}

	event->adt_hotplug_state.auth_used = auth;
	event->adt_hotplug_state.device_path = path;
	event->adt_hotplug_state.connection = connection;
	event->adt_hotplug_state.new_state = state_str(new_state);
	event->adt_hotplug_state.old_state = state_str(old_state);

	/* Put the event */
	if (adt_put_event(event, pass_fail, fail_reason) != 0)
		log_err("Cannot put audit event.\n");

	adt_free_event(event);
	(void) adt_end_session(session);
}

/*
 * audit_setprivate()
 *
 *	Audit a 'set private' door command.
 */
static void
audit_setprivate(ucred_t *ucred, char *auth, char *path, char *connection,
    char *options, int result)
{
	adt_session_data_t	*session;
	adt_event_data_t	*event;
	int			pass_fail, fail_reason;

	if (audit_session(ucred, &session) != 0)
		return;

	if ((event = adt_alloc_event(session, ADT_hotplug_set)) == NULL) {
		(void) adt_end_session(session);
		return;
	}

	if (result == 0) {
		pass_fail = ADT_SUCCESS;
		fail_reason = ADT_SUCCESS;
	} else {
		pass_fail = ADT_FAILURE;
		fail_reason = result;
	}

	event->adt_hotplug_set.auth_used = auth;
	event->adt_hotplug_set.device_path = path;
	event->adt_hotplug_set.connection = connection;
	event->adt_hotplug_set.options = options;

	/* Put the event */
	if (adt_put_event(event, pass_fail, fail_reason) != 0)
		log_err("Cannot put audit event.\n");

	adt_free_event(event);
	(void) adt_end_session(session);
}

/*
 * state_str()
 *
 *	Convert a state from integer to string.
 */
static char *
state_str(int state)
{
	switch (state) {
	case DDI_HP_CN_STATE_EMPTY:
		return ("EMPTY");
	case DDI_HP_CN_STATE_PRESENT:
		return ("PRESENT");
	case DDI_HP_CN_STATE_POWERED:
		return ("POWERED");
	case DDI_HP_CN_STATE_ENABLED:
		return ("ENABLED");
	case DDI_HP_CN_STATE_PORT_EMPTY:
		return ("PORT-EMPTY");
	case DDI_HP_CN_STATE_PORT_PRESENT:
		return ("PORT-PRESENT");
	case DDI_HP_CN_STATE_OFFLINE:
		return ("OFFLINE");
	case DDI_HP_CN_STATE_ATTACHED:
		return ("ATTACHED");
	case DDI_HP_CN_STATE_MAINTENANCE:
		return ("MAINTENANCE");
	case DDI_HP_CN_STATE_ONLINE:
		return ("ONLINE");
	default:
		return ("UNKNOWN");
	}
}