ReactOS 0.4.15-dev-5666-gc548b97
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
27typedef struct _pci_device
28{
37
39
40static void lspci_send(RDPCLIENT * This, const char *output);
41
42
43/* Handle one line of output from the lspci subprocess */
44static BOOL
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",
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 */
109static BOOL
111{
112 char *lspci_command[5] = { "lspci", "-m", "-n", "-v", NULL };
113
114 if (!strcmp(line, "LSPCI"))
115 {
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 */
130static 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 */
151BOOL
153{
157 return (lspci_channel != NULL);
158}
159
160/* Send data to channel */
161static void
162lspci_send(RDPCLIENT * This, const char *output)
163{
164 STREAM s;
165 size_t len;
166
167 len = strlen(output);
169 out_uint8p(s, output, len) s_mark_end(s);
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}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
VCHANNEL * channel_register(char *name, uint32 flags, void(*callback)(STREAM))
Definition: channels.c:46
STREAM channel_init(VCHANNEL *channel, uint32 length)
Definition: channels.c:69
void channel_send(STREAM s, VCHANNEL *channel)
Definition: channels.c:79
#define CHANNEL_OPTION_ENCRYPT_RDP
Definition: constants.h:432
#define CHANNEL_OPTION_INITIALIZED
Definition: constants.h:431
#define s_mark_end(s)
Definition: parse.h:41
#define out_uint8p(s, v, n)
Definition: parse.h:93
void xfree(void *mem)
Definition: uimain.c:758
RD_BOOL str_startswith(const char *s, const char *prefix)
Definition: rdesktop.c:1235
RD_BOOL str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
void hexdump(unsigned char *p, unsigned int len)
Definition: shimdbg.c:234
void * xmalloc(int size)
Definition: uimain.c:747
RD_BOOL lspci_init(void)
RD_BOOL subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
unsigned short uint16
Definition: types.h:30
#define True
Definition: types.h:24
unsigned char uint8
Definition: types.h:28
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
#define printf
Definition: freeldr.h:94
GLdouble s
Definition: gl.h:2039
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
struct _pci_device pci_device
static void lspci_process(RDPCLIENT *This, STREAM s)
Definition: lspci.c:131
static VCHANNEL * lspci_channel
Definition: lspci.c:25
static BOOL handle_child_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:45
static void lspci_send(RDPCLIENT *This, const char *output)
Definition: lspci.c:162
static pci_device current_device
Definition: lspci.c:38
static BOOL lspci_process_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:110
#define error(str)
Definition: mkdosfs.c:1605
_Check_return_ _CRTIMP size_t __cdecl strspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
#define warning(s)
Definition: debug.h:83
#define memset(x, y, z)
Definition: compat.h:39
uint8 progif
Definition: lspci.c:35
uint16 subdevice
Definition: lspci.c:33
uint16 device
Definition: lspci.c:31
uint16 vendor
Definition: lspci.c:30
uint16 klass
Definition: lspci.c:29
uint8 revision
Definition: lspci.c:34
uint16 subvendor
Definition: lspci.c:32
Definition: parser.c:49
Definition: parse.h:23
#define snprintf
Definition: wintirpc.h:48