Received: by 10.223.185.116 with SMTP id b49csp5493061wrg; Wed, 7 Mar 2018 12:44:30 -0800 (PST) X-Google-Smtp-Source: AG47ELuI40gJw0aCncUdahiE4r+lfEbDKVzjTdxa5rX+TxrGdDj7w2nHhIROokJUpGXzgS7A4ebq X-Received: by 2002:a17:902:f81:: with SMTP id 1-v6mr20989395plz.265.1520455470018; Wed, 07 Mar 2018 12:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520455469; cv=none; d=google.com; s=arc-20160816; b=R5hC3PPKsJhKi7cjtB7fahn/UUCTfLtGpP74uQX+oBckgRq6lb6MPgVWbM2md7ghKs hfZchk7ZwSFF81Nd+a/2cSSalZ3vpa6drUreiCAqhH5nv2AQTBasKNlzj9wNqLiNkPwL uvIs3FUSTDb0mAPKOO816avP39ecJOTU+58QQTuT+UjEVLh2ZuFX05H/Jz0U25ZaQ642 8BAfg7in7Iv8uYL7RC0RFU1clD47Fy/Q1XFq/eVfneDExjEkanAxepihNRjou8qXnFFj 80DUJngn9tyZhEos+kIBuoXxopgCS18raQpfe2ZO2nixhiKKkJxmxdn3Em46ykSCamod FP6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AIGGP653X2rTn1yiVeU83RlVjDGwwvQcvDTyxFDOvDw=; b=NEF2m39GVcbB/daNkdNnUil57dKmnAGIsWAhgpEoGDke/E/axWcK4pXJZaDoseJp4Y 3QwHMLchROdURnUH5EtJq3o71X8XSBv4L7TNZDVGMWzTnzPB1X3YyqaxRFRLJZtp1hC6 7Ke7rGbIUtiGXGTfJxrM+RaA7mYPBpUnlbVwNjZTomC2vDQVNv/gnCK8kRRMWmt6BzJ4 vo9C4FCAXymC5d831EVi3blJvF4I1tCLMzu71Qfl/nqmLD4lBVlcNJ7Fvm8E5DgbXkSm cJ5wa+keeIdMCvRoyJlq4gQ0/UeReBkwHotV4TBy9V83agwsrm+L9Ge+viiZsh64mjz9 cjSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si14487020pfh.153.2018.03.07.12.44.15; Wed, 07 Mar 2018 12:44:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935064AbeCGUm4 (ORCPT + 99 others); Wed, 7 Mar 2018 15:42:56 -0500 Received: from osg.samsung.com ([64.30.133.232]:55326 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934701AbeCGUmu (ORCPT ); Wed, 7 Mar 2018 15:42:50 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 6273A3FBBF; Wed, 7 Mar 2018 12:42:50 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id loGXCE96r5eZ; Wed, 7 Mar 2018 12:42:48 -0800 (PST) Received: from localhost.localdomain (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) by osg.samsung.com (Postfix) with ESMTPSA id 588243FBA5; Wed, 7 Mar 2018 12:42:48 -0800 (PST) From: Shuah Khan To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org Cc: Shuah Khan , yuyang.du@intel.com, k.opasiak@samsung.com, nobuo.iwata@fujixerox.co.jp, julien.boibessot@armadeus.com, jdieter@lesbg.com, peter.senna@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] usbip: tools: add more error codes for usbip request/reply messages Date: Wed, 7 Mar 2018 13:42:24 -0700 Message-Id: <6add3ebef26ac0a498696ae4e30c44a3af87fe47.1520455011.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently ST_OK and ST_NA are the only values defined to communicate status of a request from a client. Add more error codes to clearly indicate what failed. For example, when client sends request to import a device that isn't export-able, server can send a specific error code to the client. Existing defines are moved to a common header in libsrc to be included in the libusbip_la-usbip_common.o to be used by all the usbip tools. Supporting interface to print error strings is added to the common lib. Signed-off-by: Shuah Khan --- tools/usb/usbip/libsrc/usbip_common.c | 23 +++++++++++++++++++++++ tools/usb/usbip/libsrc/usbip_common.h | 11 +++++++++++ tools/usb/usbip/src/usbip_network.h | 4 +--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c index 001bb8e8f668..bb424638d75b 100644 --- a/tools/usb/usbip/libsrc/usbip_common.c +++ b/tools/usb/usbip/libsrc/usbip_common.c @@ -66,6 +66,29 @@ const char *usbip_speed_string(int num) return "Unknown Speed"; } +struct op_common_status_string { + int num; + char *desc; +}; + +static struct op_common_status_string op_common_status_strings[] = { + { ST_OK, "Request Completed Successfully" }, + { ST_NA, "Request Failed" }, + { ST_DEV_BUSY, "Device busy (exported)" }, + { ST_DEV_ERR, "Device in error state" }, + { ST_NODEV, "Device not found" }, + { ST_ERROR, "Unexpected response" }, + { 0, NULL} +}; + +const char *usbip_op_common_status_string(int status) +{ + for (int i = 0; op_common_status_strings[i].desc != NULL; i++) + if (op_common_status_strings[i].num == status) + return op_common_status_strings[i].desc; + + return "Unknown Op Common Status"; +} #define DBG_UDEV_INTEGER(name)\ dbg("%-20s = %x", to_string(name), (int) udev->name) diff --git a/tools/usb/usbip/libsrc/usbip_common.h b/tools/usb/usbip/libsrc/usbip_common.h index e45ec9d2fdbc..73a367a7fa10 100644 --- a/tools/usb/usbip/libsrc/usbip_common.h +++ b/tools/usb/usbip/libsrc/usbip_common.h @@ -43,6 +43,16 @@ #define SYSFS_PATH_MAX 256 #define SYSFS_BUS_ID_SIZE 32 +/* Defines for op_code status in server/client op_common PDUs */ +#define ST_OK 0x00 +#define ST_NA 0x01 + /* Device requested for import is not available */ +#define ST_DEV_BUSY 0x02 + /* Device requested for import is in error state */ +#define ST_DEV_ERR 0x03 +#define ST_NODEV 0x04 +#define ST_ERROR 0x05 + extern int usbip_use_syslog; extern int usbip_use_stderr; extern int usbip_use_debug ; @@ -130,6 +140,7 @@ int read_usb_interface(struct usbip_usb_device *udev, int i, const char *usbip_speed_string(int num); const char *usbip_status_string(int32_t status); +const char *usbip_op_common_status_string(int status); int usbip_names_init(char *); void usbip_names_free(void); diff --git a/tools/usb/usbip/src/usbip_network.h b/tools/usb/usbip/src/usbip_network.h index 7032687621d3..b6a2f9be888c 100644 --- a/tools/usb/usbip/src/usbip_network.h +++ b/tools/usb/usbip/src/usbip_network.h @@ -27,9 +27,7 @@ struct op_common { #define OP_REPLY (0x00 << 8) uint16_t code; - /* add more error code */ -#define ST_OK 0x00 -#define ST_NA 0x01 + /* status codes defined in usbip_common.h */ uint32_t status; /* op_code status (for reply) */ } __attribute__((packed)); -- 2.14.1