2015-07-16 10:40:48 -06:00
|
|
|
/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
|
2014-03-04 06:58:07 -07:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2015-07-16 10:40:48 -06:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2014-03-04 06:58:07 -07:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VBUSDEVICEINFO_H__
|
|
|
|
#define __VBUSDEVICEINFO_H__
|
|
|
|
|
2014-08-02 20:03:43 -06:00
|
|
|
#include <linux/types.h>
|
2014-03-04 06:58:07 -07:00
|
|
|
|
|
|
|
#pragma pack(push, 1) /* both GCC and VC now allow this pragma */
|
|
|
|
|
|
|
|
/* An array of this struct is present in the channel area for each vbus.
|
|
|
|
* (See vbuschannel.h.)
|
|
|
|
* It is filled in by the client side to provide info about the device
|
|
|
|
* and driver from the client's perspective.
|
|
|
|
*/
|
2014-10-03 12:09:18 -06:00
|
|
|
struct ultra_vbus_deviceinfo {
|
|
|
|
u8 devtype[16]; /* short string identifying the device type */
|
|
|
|
u8 drvname[16]; /* driver .sys file name */
|
|
|
|
u8 infostrs[96]; /* sequence of tab-delimited id strings: */
|
2014-03-04 06:58:07 -07:00
|
|
|
/* <DRIVER_REV> <DRIVER_VERTAG> <DRIVER_COMPILETIME> */
|
2014-07-29 13:09:40 -06:00
|
|
|
u8 reserved[128]; /* pad size to 256 bytes */
|
2014-10-03 12:09:18 -06:00
|
|
|
};
|
2014-03-04 06:58:07 -07:00
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
/* Reads chars from the buffer at <src> for <srcmax> bytes, and writes to
|
|
|
|
* the buffer at <p>, which is <remain> bytes long, ensuring never to
|
|
|
|
* overflow the buffer at <p>, using the following rules:
|
|
|
|
* - printable characters are simply copied from the buffer at <src> to the
|
|
|
|
* buffer at <p>
|
|
|
|
* - intervening streaks of non-printable characters in the buffer at <src>
|
|
|
|
* are replaced with a single space in the buffer at <p>
|
|
|
|
* Note that we pay no attention to '\0'-termination.
|
|
|
|
* Returns the number of bytes written to <p>.
|
|
|
|
*
|
|
|
|
* Pass <p> == NULL and <remain> == 0 for this special behavior. In this
|
|
|
|
* case, we simply return the number of bytes that WOULD HAVE been written
|
|
|
|
* to a buffer at <p>, had it been infinitely big.
|
|
|
|
*/
|
|
|
|
static inline int
|
2014-07-03 09:02:18 -06:00
|
|
|
vbuschannel_sanitize_buffer(char *p, int remain, char *src, int srcmax)
|
2014-03-04 06:58:07 -07:00
|
|
|
{
|
|
|
|
int chars = 0;
|
|
|
|
int nonprintable_streak = 0;
|
2014-08-05 12:57:54 -06:00
|
|
|
|
2014-03-04 06:58:07 -07:00
|
|
|
while (srcmax > 0) {
|
2014-07-03 09:02:18 -06:00
|
|
|
if ((*src >= ' ') && (*src < 0x7f)) {
|
2014-03-04 06:58:07 -07:00
|
|
|
if (nonprintable_streak) {
|
|
|
|
if (remain > 0) {
|
|
|
|
*p = ' ';
|
|
|
|
p++;
|
|
|
|
remain--;
|
|
|
|
chars++;
|
2016-02-08 08:41:42 -07:00
|
|
|
} else if (!p) {
|
2014-03-04 06:58:07 -07:00
|
|
|
chars++;
|
2014-10-23 12:29:40 -06:00
|
|
|
}
|
2014-03-04 06:58:07 -07:00
|
|
|
nonprintable_streak = 0;
|
|
|
|
}
|
|
|
|
if (remain > 0) {
|
2014-07-03 09:02:18 -06:00
|
|
|
*p = *src;
|
2014-03-04 06:58:07 -07:00
|
|
|
p++;
|
|
|
|
remain--;
|
|
|
|
chars++;
|
2016-02-08 08:41:42 -07:00
|
|
|
} else if (!p) {
|
2014-03-04 06:58:07 -07:00
|
|
|
chars++;
|
2014-10-23 12:29:40 -06:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-04 06:58:07 -07:00
|
|
|
nonprintable_streak = 1;
|
2014-10-23 12:29:40 -06:00
|
|
|
}
|
2014-03-04 06:58:07 -07:00
|
|
|
src++;
|
|
|
|
srcmax--;
|
|
|
|
}
|
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VBUSCHANNEL_ADDACHAR(ch, p, remain, chars) \
|
|
|
|
do { \
|
|
|
|
if (remain <= 0) \
|
|
|
|
break; \
|
|
|
|
*p = ch; \
|
|
|
|
p++; chars++; remain--; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Converts the non-negative value at <num> to an ascii decimal string
|
|
|
|
* at <p>, writing at most <remain> bytes. Note there is NO '\0' termination
|
|
|
|
* written to <p>.
|
|
|
|
*
|
|
|
|
* Returns the number of bytes written to <p>.
|
|
|
|
*
|
|
|
|
* Note that we create this function because we need to do this operation in
|
|
|
|
* an environment-independent way (since we are in a common header file).
|
|
|
|
*/
|
|
|
|
static inline int
|
2014-07-03 09:02:15 -06:00
|
|
|
vbuschannel_itoa(char *p, int remain, int num)
|
2014-03-04 06:58:07 -07:00
|
|
|
{
|
|
|
|
int digits = 0;
|
|
|
|
char s[32];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
|
|
/* '0' is a special case */
|
|
|
|
if (remain <= 0)
|
|
|
|
return 0;
|
|
|
|
*p = '0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* form a backwards decimal ascii string in <s> */
|
|
|
|
while (num > 0) {
|
2014-10-23 12:29:43 -06:00
|
|
|
if (digits >= (int)sizeof(s))
|
2014-03-04 06:58:07 -07:00
|
|
|
return 0;
|
|
|
|
s[digits++] = (num % 10) + '0';
|
|
|
|
num = num / 10;
|
|
|
|
}
|
|
|
|
if (remain < digits) {
|
|
|
|
/* not enough room left at <p> to hold number, so fill with
|
2016-02-08 08:41:43 -07:00
|
|
|
* '?'
|
|
|
|
*/
|
2014-03-04 06:58:07 -07:00
|
|
|
for (i = 0; i < remain; i++, p++)
|
|
|
|
*p = '?';
|
|
|
|
return remain;
|
|
|
|
}
|
|
|
|
/* plug in the decimal ascii string representing the number, by */
|
|
|
|
/* reversing the string we just built in <s> */
|
|
|
|
i = digits;
|
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
*p = s[i];
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return digits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads <devInfo>, and converts its contents to a printable string at <p>,
|
|
|
|
* writing at most <remain> bytes. Note there is NO '\0' termination
|
|
|
|
* written to <p>.
|
|
|
|
*
|
|
|
|
* Pass <devix> >= 0 if you want a device index presented.
|
|
|
|
*
|
|
|
|
* Returns the number of bytes written to <p>.
|
|
|
|
*/
|
|
|
|
static inline int
|
2014-10-03 12:09:18 -06:00
|
|
|
vbuschannel_devinfo_to_string(struct ultra_vbus_deviceinfo *devinfo,
|
2014-10-23 12:29:41 -06:00
|
|
|
char *p, int remain, int devix)
|
2014-03-04 06:58:07 -07:00
|
|
|
{
|
2014-07-03 09:02:18 -06:00
|
|
|
char *psrc;
|
2014-03-04 06:58:07 -07:00
|
|
|
int nsrc, x, i, pad;
|
|
|
|
int chars = 0;
|
|
|
|
|
2014-10-23 12:29:42 -06:00
|
|
|
psrc = &devinfo->devtype[0];
|
2014-10-03 12:09:18 -06:00
|
|
|
nsrc = sizeof(devinfo->devtype);
|
2014-07-03 09:02:15 -06:00
|
|
|
if (vbuschannel_sanitize_buffer(NULL, 0, psrc, nsrc) <= 0)
|
2014-03-04 06:58:07 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* emit device index */
|
|
|
|
if (devix >= 0) {
|
|
|
|
VBUSCHANNEL_ADDACHAR('[', p, remain, chars);
|
2014-07-03 09:02:15 -06:00
|
|
|
x = vbuschannel_itoa(p, remain, devix);
|
2014-03-04 06:58:07 -07:00
|
|
|
p += x;
|
|
|
|
remain -= x;
|
|
|
|
chars += x;
|
|
|
|
VBUSCHANNEL_ADDACHAR(']', p, remain, chars);
|
|
|
|
} else {
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* emit device type */
|
2014-07-03 09:02:15 -06:00
|
|
|
x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc);
|
2014-03-04 06:58:07 -07:00
|
|
|
p += x;
|
|
|
|
remain -= x;
|
|
|
|
chars += x;
|
|
|
|
pad = 15 - x; /* pad device type to be exactly 15 chars */
|
|
|
|
for (i = 0; i < pad; i++)
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
|
|
|
|
/* emit driver name */
|
2014-10-23 12:29:42 -06:00
|
|
|
psrc = &devinfo->drvname[0];
|
2014-10-03 12:09:18 -06:00
|
|
|
nsrc = sizeof(devinfo->drvname);
|
2014-07-03 09:02:15 -06:00
|
|
|
x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc);
|
2014-03-04 06:58:07 -07:00
|
|
|
p += x;
|
|
|
|
remain -= x;
|
|
|
|
chars += x;
|
|
|
|
pad = 15 - x; /* pad driver name to be exactly 15 chars */
|
|
|
|
for (i = 0; i < pad; i++)
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
|
|
|
|
|
|
|
|
/* emit strings */
|
2014-10-23 12:29:42 -06:00
|
|
|
psrc = &devinfo->infostrs[0];
|
2014-10-03 12:09:18 -06:00
|
|
|
nsrc = sizeof(devinfo->infostrs);
|
2014-07-03 09:02:15 -06:00
|
|
|
x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc);
|
2014-03-04 06:58:07 -07:00
|
|
|
p += x;
|
|
|
|
remain -= x;
|
|
|
|
chars += x;
|
|
|
|
VBUSCHANNEL_ADDACHAR('\n', p, remain, chars);
|
|
|
|
|
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|