fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdarg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <syslog.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libdevice.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fibre-channel/fcio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "common.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int parse_line(char *line, char *path, char *wwn, char *filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int create_ap_instance(char *ap_id, char *wwn_string,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *filename, char *line);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void log_error(char *msg_id, char *input_tmplt, ...);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char ctoi(char c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Simple wrapper for syslog error messages.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allows easy addition of syserr output if desired.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelog_error(char *msg_id, char *input_tmplt, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_list ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char input_merged_msg[200];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *msg_template = "ID[luxadm.create_fabric_device.%s] %s";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First %s for msg_id in merged msg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Second %s is for input merged_msg
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *merged_msg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_start(ap, input_tmplt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert caller's args */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) vsprintf(input_merged_msg, input_tmplt, ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte va_end(ap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte merged_msg = (char *)malloc(strlen(msg_template) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(input_merged_msg) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(msg_id) + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (merged_msg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ID[luxadm.create_fabric_device.2317] "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "malloc failure, %s", strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(merged_msg, msg_template, msg_id, input_merged_msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first insert msg_id */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, merged_msg, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) puts(merged_msg); /* also print message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(merged_msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Routines for reading tapestry repository file
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define COMMENT_CHAR '#'
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteread_repos_file(char *repos_filename)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *line;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tmp_ptr, *mmap_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char path[MAXPATHLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char wwn[FC_WWN_SIZE*2+1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat stbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int filesize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int bytes_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (repos_filename == NULL || *repos_filename == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2310",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "filename missing for -f option of "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "luxadm -e create_fabric_device");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(repos_filename, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2311",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "fopen failed: cannot open repository file %s. %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte repos_filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fstat(fd, &stbuf) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2312",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stat failed on file %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte repos_filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte filesize = stbuf.st_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_ptr = mmap_ptr = mmap((caddr_t)0, filesize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (PROT_READ | PROT_WRITE), MAP_PRIVATE, fd, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mmap_ptr == MAP_FAILED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2315",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to mmap file %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte repos_filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_read = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (bytes_read < filesize) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line = tmp_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (bytes_read < filesize && *tmp_ptr != '\n') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_read++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_ptr++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*tmp_ptr == '\n') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tmp_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_ptr++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_read++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If the line is a comment, read another line */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*line == COMMENT_CHAR) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = parse_line(line, path, wwn, repos_filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = create_ap_instance(path,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn, repos_filename, line);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = munmap(mmap_ptr, filesize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Input is paramater 1 - a line from repository
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Output is other parameters, the path to the attachment point,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the port wwn are parsed from the repository
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Format is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "/devices/pci..../fp@1,0:fc::wwn"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If controller name is missing, that's okay. Other fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must be present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return 0 on success or -1 on failure; all failures logged to syslog.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WWN_DELIM "::"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteparse_line(char *line, char *path, char *wwn, char *filename)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p_path, *p_wwn, *p_delim;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *line_copy;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line_copy = strdup(line);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (line_copy == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2317",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "malloc failure, %s", strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_path = line_copy;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_delim = strstr(p_path, WWN_DELIM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p_delim == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2313",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Invalid line (%s) in file %s.", line, filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(line_copy);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p_delim = NULL; /* NULL terminate path */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlcpy(path, p_path, MAXPATHLEN) >= MAXPATHLEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2318",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Path too long (%s) in file %s.", p_path, filename);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(line_copy);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_wwn = p_delim + strlen(WWN_DELIM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now look for the blank delimiter before the controller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is just the case when there may be a controller #
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after the attachment point and WWN. For example -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * /devices/pci@b,2000/pci@2/SUNW,qlc@4/fp@0,0:fc::220000203707f4f1 c4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_delim = strchr(p_wwn, ' ');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p_delim != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* now p_delim points to blank */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p_delim = NULL; /* terminate wwn at delim */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p_last_char;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p_last_char = p_wwn+strlen(p_wwn)-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*p_last_char == '\n') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p_last_char = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcpy(wwn, p_wwn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(line_copy);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic char
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortectoi(char c)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((c >= '0') && (c <= '9'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c -= '0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((c >= 'A') && (c <= 'F'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = c - 'A' + 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((c >= 'a') && (c <= 'f'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = c - 'a' + 10;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (c);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "string" is Input and "port_wwn" has the output
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function converts a string to WWN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For example a string like
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "220000203707F4F1" gets converted to 0x220000203707F4F1 ...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * where
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[0] = 0x22,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[1] = 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[2] = 0x00,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[3] = 0x20,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[4] = 0x37,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[5] = 0x07,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[6] = 0xF4, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port_wwn[7] = 0xF1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestring_to_wwn(const uchar_t *string, uchar_t *port_wwn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c, c1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *wwnp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwnp = port_wwn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < WWN_SIZE; i++, wwnp++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = ctoi(*string++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c1 = ctoi(*string++);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c == -1 || c1 == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *wwnp = ((c << 4) + c1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_ap_instance(char *ap_id, char *wwn_string,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *filename, char *line)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_hdl_t bus_handle, dev_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_ddef_t ddef_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t wwn_array[FC_WWN_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddef_handle = devctl_ddef_alloc("dummy", 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddef_handle == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2314",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line, filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * g_string_to_wwn() has not been used here because it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prepends 2 NULLs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (string_to_wwn((uchar_t *)wwn_string, wwn_array) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2314",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line, filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_ddef_free(ddef_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) devctl_ddef_byte_array(ddef_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "port-wwn", FC_WWN_SIZE, wwn_array);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bus_handle = devctl_bus_acquire(ap_id, 0)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_ddef_free(ddef_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2314",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Internal error to process line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line, filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_bus_dev_create(bus_handle, ddef_handle, 0, &dev_handle)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_ddef_free(ddef_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_release(bus_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte log_error("2316",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "configuration failed for line (%s) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "in file: %s. %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line, filename, strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_release(dev_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_ddef_free(ddef_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devctl_release(bus_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}