17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*d29f5a71Szhigang lu - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License"). 6*d29f5a71Szhigang lu - Sun Microsystems - Beijing China * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*d29f5a71Szhigang lu - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*d29f5a71Szhigang lu - Sun Microsystems - Beijing China * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _CFGA_USB_H 277c478bd9Sstevel@tonic-gate #define _CFGA_USB_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <stdlib.h> 357c478bd9Sstevel@tonic-gate #include <strings.h> 367c478bd9Sstevel@tonic-gate #include <fcntl.h> 377c478bd9Sstevel@tonic-gate #include <ctype.h> 387c478bd9Sstevel@tonic-gate #include <unistd.h> 397c478bd9Sstevel@tonic-gate #include <libintl.h> 407c478bd9Sstevel@tonic-gate #include <libdevice.h> 417c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 427c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h> 437c478bd9Sstevel@tonic-gate #include <sys/usb/hubd/hub.h> 447c478bd9Sstevel@tonic-gate #include <sys/usb/hubd/hubd_impl.h> 457c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 467c478bd9Sstevel@tonic-gate #include <libdevice.h> 477c478bd9Sstevel@tonic-gate #include <librcm.h> 487c478bd9Sstevel@tonic-gate #include <synch.h> 497c478bd9Sstevel@tonic-gate #include <thread.h> 507c478bd9Sstevel@tonic-gate #include <assert.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define CFGA_PLUGIN_LIB 537c478bd9Sstevel@tonic-gate #include <config_admin.h> 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * Debug stuff. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate #ifdef DEBUG 60*d29f5a71Szhigang lu - Sun Microsystems - Beijing China #define DPRINTF (void) printf 617c478bd9Sstevel@tonic-gate #else 627c478bd9Sstevel@tonic-gate #define DPRINTF 0 && 637c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* for walking links */ 677c478bd9Sstevel@tonic-gate typedef struct walk_link { 687c478bd9Sstevel@tonic-gate char *path; 697c478bd9Sstevel@tonic-gate char len; 707c478bd9Sstevel@tonic-gate char **linkpp; 717c478bd9Sstevel@tonic-gate } walk_link_t; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * Stuff carried over for the routines borrowed from cfgadm/SCSI. 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate typedef enum { 787c478bd9Sstevel@tonic-gate UCFGA_TERMINATE = 0, 797c478bd9Sstevel@tonic-gate UCFGA_CONTINUE 807c478bd9Sstevel@tonic-gate } ucfga_recur_t; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* Structures for tree walking code */ 837c478bd9Sstevel@tonic-gate typedef struct { 847c478bd9Sstevel@tonic-gate char *phys; 857c478bd9Sstevel@tonic-gate char *log; 867c478bd9Sstevel@tonic-gate int ret; 877c478bd9Sstevel@tonic-gate int match_minor; 887c478bd9Sstevel@tonic-gate int l_errno; 897c478bd9Sstevel@tonic-gate } pathm_t; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define MATCH_MINOR_NAME 1 937c478bd9Sstevel@tonic-gate #define S_FREE(x) (((x) != NULL) ? (free(x), (x) = NULL) : (void *)0) 947c478bd9Sstevel@tonic-gate #define GET_DYN(a) (((a) != NULL) ? strstr((a), DYN_SEP) : (void *)0) 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* Location of USB configuration file */ 987c478bd9Sstevel@tonic-gate #define USBCONF_FILE "/etc/usb/config_map.conf" 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* Hardware options */ 1017c478bd9Sstevel@tonic-gate #define OPT_DISABLE_RCM "disable_rcm" 1027c478bd9Sstevel@tonic-gate #define FLAG_DISABLE_RCM 0x00000001 /* flags */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* Return/error codes */ 1057c478bd9Sstevel@tonic-gate typedef enum { 1067c478bd9Sstevel@tonic-gate UCFGA_ERR = -2, 1077c478bd9Sstevel@tonic-gate UCFGA_LIB_ERR, 1087c478bd9Sstevel@tonic-gate UCFGA_OK, 1097c478bd9Sstevel@tonic-gate UCFGA_BUSY, 1107c478bd9Sstevel@tonic-gate UCFGA_NO_REC 1117c478bd9Sstevel@tonic-gate } ucfga_ret_t; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* Messages */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate typedef struct { 1187c478bd9Sstevel@tonic-gate int intl; /* Flag: if 1, internationalize */ 1197c478bd9Sstevel@tonic-gate cfga_err_t cfga_err; /* Error code libcfgadm understands */ 1207c478bd9Sstevel@tonic-gate const char *msgstr; 1217c478bd9Sstevel@tonic-gate } msgcvt_t; 1227c478bd9Sstevel@tonic-gate #define NO_CVT 0 1237c478bd9Sstevel@tonic-gate #define CVT 1 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate #define MSG_TBL_SZ(table) (sizeof ((table)) / sizeof (msgcvt_t)) 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* Error message ids (and indices into usb_error_msgs) */ 1297c478bd9Sstevel@tonic-gate typedef enum { 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate CFGA_USB_OK = 0, 1327c478bd9Sstevel@tonic-gate CFGA_USB_UNKNOWN, 1337c478bd9Sstevel@tonic-gate CFGA_USB_INTERNAL_ERROR, 1347c478bd9Sstevel@tonic-gate CFGA_USB_OPTIONS, 1357c478bd9Sstevel@tonic-gate CFGA_USB_DYNAMIC_AP, 1367c478bd9Sstevel@tonic-gate CFGA_USB_AP, 1377c478bd9Sstevel@tonic-gate CFGA_USB_PORT, 1387c478bd9Sstevel@tonic-gate CFGA_USB_DEVCTL, 1397c478bd9Sstevel@tonic-gate CFGA_USB_NOT_CONNECTED, 1407c478bd9Sstevel@tonic-gate CFGA_USB_NOT_CONFIGURED, 1417c478bd9Sstevel@tonic-gate CFGA_USB_ALREADY_CONNECTED, 1427c478bd9Sstevel@tonic-gate CFGA_USB_ALREADY_CONFIGURED, 1437c478bd9Sstevel@tonic-gate CFGA_USB_OPEN, 1447c478bd9Sstevel@tonic-gate CFGA_USB_IOCTL, 1457c478bd9Sstevel@tonic-gate CFGA_USB_BUSY, 1467c478bd9Sstevel@tonic-gate CFGA_USB_ALLOC_FAIL, 1477c478bd9Sstevel@tonic-gate CFGA_USB_OPNOTSUPP, 1487c478bd9Sstevel@tonic-gate CFGA_USB_DEVLINK, 1497c478bd9Sstevel@tonic-gate CFGA_USB_STATE, 1507c478bd9Sstevel@tonic-gate CFGA_USB_CONFIG_INVAL, 1517c478bd9Sstevel@tonic-gate CFGA_USB_PRIV, 1527c478bd9Sstevel@tonic-gate CFGA_USB_NVLIST, 1537c478bd9Sstevel@tonic-gate CFGA_USB_ZEROLEN, 1547c478bd9Sstevel@tonic-gate CFGA_USB_CONFIG_FILE, 1557c478bd9Sstevel@tonic-gate CFGA_USB_LOCK_FILE, 1567c478bd9Sstevel@tonic-gate CFGA_USB_UNLOCK_FILE, 1577c478bd9Sstevel@tonic-gate CFGA_USB_ONE_CONFIG, 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* RCM Errors */ 1607c478bd9Sstevel@tonic-gate CFGA_USB_RCM_HANDLE, 1617c478bd9Sstevel@tonic-gate CFGA_USB_RCM_ONLINE, 1627c478bd9Sstevel@tonic-gate CFGA_USB_RCM_OFFLINE, 1637c478bd9Sstevel@tonic-gate CFGA_USB_RCM_INFO 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate } cfga_usb_ret_t; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * Given an error msg index, look up the associated string, and 1707c478bd9Sstevel@tonic-gate * convert it to the current locale if required. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate #define ERR_STR(msg_idx) \ 1737c478bd9Sstevel@tonic-gate (get_msg((msg_idx), usb_error_msgs, MSG_TBL_SZ(usb_error_msgs))) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* Misc text strings */ 1777c478bd9Sstevel@tonic-gate #define CFGA_DEV_DIR "/dev/cfg" 1787c478bd9Sstevel@tonic-gate #define DYN_SEP "::" 1797c478bd9Sstevel@tonic-gate #define MINOR_SEP ":" 1807c478bd9Sstevel@tonic-gate #define PORT "port" 1817c478bd9Sstevel@tonic-gate #define PORT_SEPERATOR "." 1827c478bd9Sstevel@tonic-gate #define USB "usb" 1837c478bd9Sstevel@tonic-gate #define USB_CFGADM_DEFAULT_AP_TYPE "unknown" 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* these set of defines are -lav listing */ 1867c478bd9Sstevel@tonic-gate #define USB_UNDEF_STR "<undef>" 1877c478bd9Sstevel@tonic-gate #define USB_NO_CFG_STR "<no cfg str descr>" 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* -x commands */ 1907c478bd9Sstevel@tonic-gate #define RESET_DEVICE "usb_reset" /* with -x option */ 1917c478bd9Sstevel@tonic-gate #define USB_CONFIG "usb_config" /* with -x option */ 1927c478bd9Sstevel@tonic-gate #define SET_CONFIG "config=" /* with -o option */ 1937c478bd9Sstevel@tonic-gate #define SET_DRIVER "drv=" /* with -op option */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* for confirm operation */ 1967c478bd9Sstevel@tonic-gate #define USB_CONFIRM_0 "the device: " 1977c478bd9Sstevel@tonic-gate #define USB_CONFIRM_1 \ 1987c478bd9Sstevel@tonic-gate "This operation will suspend activity on the USB device\nContinue" 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* Prototypes */ 2017c478bd9Sstevel@tonic-gate extern int add_entry(char *, int, int, int, char *, char *, char *, 2027c478bd9Sstevel@tonic-gate char **); 2037c478bd9Sstevel@tonic-gate extern cfga_usb_ret_t do_control_ioctl(const char *, uint_t, uint_t, 2047c478bd9Sstevel@tonic-gate void **, size_t *); 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate #endif 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate #endif /* _CFGA_USB_H */ 212