ReactOS  0.4.14-dev-57-g333b8f1
lspci.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 8 -*-
2  rdesktop: A Remote Desktop Protocol client.
3  Support for the Matrox "lspci" channel
4  Copyright (C) 2005 Matrox Graphics Inc.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 
21 #include "rdesktop.h"
22 #include <sys/types.h>
23 #include <unistd.h>
24 
26 
27 typedef struct _pci_device
28 {
36 } pci_device;
37 
39 
40 static void lspci_send(RDPCLIENT * This, const char *output);
41 
42 
43 /* Handle one line of output from the lspci subprocess */
44 static BOOL
45 handle_child_line(RDPCLIENT * This, const char *line, void *data)
46 {
47  const char *val;
48  char buf[1024];
49 
50  if (str_startswith(line, "Class:"))
51  {
52  val = line + sizeof("Class:");
53  /* Skip whitespace and second Class: occurance */
54  val += strspn(val, " \t") + sizeof("Class");
56  }
57  else if (str_startswith(line, "Vendor:"))
58  {
59  val = line + sizeof("Vendor:");
61  }
62  else if (str_startswith(line, "Device:"))
63  {
64  val = line + sizeof("Device:");
65  /* Sigh, there are *two* lines tagged as Device:. We
66  are not interested in the domain/bus/slot/func */
67  if (!strchr(val, ':'))
69  }
70  else if (str_startswith(line, "SVendor:"))
71  {
72  val = line + sizeof("SVendor:");
74  }
75  else if (str_startswith(line, "SDevice:"))
76  {
77  val = line + sizeof("SDevice:");
79  }
80  else if (str_startswith(line, "Rev:"))
81  {
82  val = line + sizeof("Rev:");
84  }
85  else if (str_startswith(line, "ProgIf:"))
86  {
87  val = line + sizeof("ProgIf:");
89  }
90  else if (strspn(line, " \t") == strlen(line))
91  {
92  /* Blank line. Send collected information over channel */
93  snprintf(buf, sizeof(buf), "%04x,%04x,%04x,%04x,%04x,%02x,%02x\n",
98  memset(&current_device, 0, sizeof(current_device));
99  }
100  else
101  {
102  warning("lspci: Unrecoqnized line '%s'\n", line);
103  }
104  return True;
105 }
106 
107 
108 /* Process one line of input from virtual channel */
109 static BOOL
110 lspci_process_line(RDPCLIENT * This, const char *line, void *data)
111 {
112  char *lspci_command[5] = { "lspci", "-m", "-n", "-v", NULL };
113 
114  if (!strcmp(line, "LSPCI"))
115  {
116  memset(&current_device, 0, sizeof(current_device));
117  subprocess(This, lspci_command, handle_child_line, NULL);
118  /* Send single dot to indicate end of enumeration */
119  lspci_send(This, ".\n");
120  }
121  else
122  {
123  error("lspci protocol error: Invalid line '%s'\n", line);
124  }
125  return True;
126 }
127 
128 
129 /* Process new data from the virtual channel */
130 static void
132 {
133  unsigned int pkglen;
134  static char *rest = NULL;
135  char *buf;
136 
137  pkglen = s->end - s->p;
138  /* str_handle_lines requires null terminated strings */
139  buf = xmalloc(pkglen + 1);
140  STRNCPY(buf, (char *) s->p, pkglen + 1);
141 #if 0
142  printf("lspci recv:\n");
143  hexdump(s->p, pkglen);
144 #endif
145 
147  xfree(buf);
148 }
149 
150 /* Initialize this module: Register the lspci channel */
151 BOOL
153 {
154  lspci_channel =
156  lspci_process);
157  return (lspci_channel != NULL);
158 }
159 
160 /* Send data to channel */
161 static void
163 {
164  STREAM s;
165  size_t len;
166 
167  len = strlen(output);
170 
171 #if 0
172  printf("lspci send:\n");
173  hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);
174 #endif
175 
177 }
uint16 vendor
Definition: lspci.c:30
#define out_uint8p(s, v, n)
Definition: parse.h:93
uint16 klass
Definition: lspci.c:29
RD_BOOL str_startswith(const char *s, const char *prefix)
Definition: rdesktop.c:1235
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define error(str)
Definition: mkdosfs.c:1605
RD_BOOL str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
BOOL lspci_init(RDPCLIENT *This)
Definition: lspci.c:152
static void lspci_process(RDPCLIENT *This, STREAM s)
Definition: lspci.c:131
#define snprintf
Definition: wintirpc.h:48
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
_Check_return_ _CRTIMP size_t __cdecl strspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
uint16 subvendor
Definition: lspci.c:32
VCHANNEL * channel_register(char *name, uint32 flags, void(*callback)(STREAM))
Definition: channels.c:46
void * xmalloc(int size)
Definition: uimain.c:747
#define CHANNEL_OPTION_INITIALIZED
Definition: constants.h:431
unsigned int BOOL
Definition: ntddk_ex.h:94
uint8 revision
Definition: lspci.c:34
uint16 device
Definition: lspci.c:31
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
GLuint GLfloat * val
Definition: glext.h:7180
static void lspci_send(RDPCLIENT *This, const char *output)
Definition: lspci.c:162
#define True
Definition: types.h:24
void xfree(void *mem)
Definition: uimain.c:758
static VCHANNEL * lspci_channel
Definition: lspci.c:25
unsigned char uint8
Definition: types.h:28
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: parse.h:22
uint16 subdevice
Definition: lspci.c:33
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
void hexdump(unsigned char *p, unsigned int len)
Definition: shimdbg.c:234
struct _pci_device pci_device
unsigned short uint16
Definition: types.h:30
static pci_device current_device
Definition: lspci.c:38
char * strchr(const char *String, int ch)
Definition: utclib.c:501
uint8 progif
Definition: lspci.c:35
static BOOL lspci_process_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:110
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
RD_BOOL subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static BOOL handle_child_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:45
#define s_mark_end(s)
Definition: parse.h:41
#define memset(x, y, z)
Definition: compat.h:39
void channel_send(STREAM s, VCHANNEL *channel)
Definition: channels.c:79
#define warning(s)
Definition: debug.h:71
#define printf
Definition: config.h:203
#define CHANNEL_OPTION_ENCRYPT_RDP
Definition: constants.h:432
STREAM channel_init(VCHANNEL *channel, uint32 length)
Definition: channels.c:69