ReactOS 0.4.15-dev-8419-g7f0e8a3
lspci.c File Reference
#include "rdesktop.h"
#include <sys/types.h>
#include <unistd.h>
Include dependency graph for lspci.c:

Go to the source code of this file.

Classes

struct  _pci_device
 

Typedefs

typedef struct _pci_device pci_device
 

Functions

static void lspci_send (RDPCLIENT *This, const char *output)
 
static BOOL handle_child_line (RDPCLIENT *This, const char *line, void *data)
 
static BOOL lspci_process_line (RDPCLIENT *This, const char *line, void *data)
 
static void lspci_process (RDPCLIENT *This, STREAM s)
 
BOOL lspci_init (RDPCLIENT *This)
 

Variables

static VCHANNELlspci_channel
 
static pci_device current_device
 

Typedef Documentation

◆ pci_device

Function Documentation

◆ handle_child_line()

static BOOL handle_child_line ( RDPCLIENT This,
const char line,
void data 
)
static

Definition at line 45 of file lspci.c.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
RD_BOOL str_startswith(const char *s, const char *prefix)
Definition: rdesktop.c:1235
#define True
Definition: types.h:24
#define NULL
Definition: types.h:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLfloat * val
Definition: glext.h:7180
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
static void lspci_send(RDPCLIENT *This, const char *output)
Definition: lspci.c:162
static pci_device current_device
Definition: lspci.c:38
_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
#define snprintf
Definition: wintirpc.h:48

Referenced by lspci_process_line().

◆ lspci_init()

BOOL lspci_init ( RDPCLIENT This)

Definition at line 152 of file lspci.c.

153{
157 return (lspci_channel != NULL);
158}
VCHANNEL * channel_register(char *name, uint32 flags, void(*callback)(STREAM))
Definition: channels.c:46
#define CHANNEL_OPTION_ENCRYPT_RDP
Definition: constants.h:432
#define CHANNEL_OPTION_INITIALIZED
Definition: constants.h:431
static void lspci_process(RDPCLIENT *This, STREAM s)
Definition: lspci.c:131
static VCHANNEL * lspci_channel
Definition: lspci.c:25

◆ lspci_process()

static void lspci_process ( RDPCLIENT This,
STREAM  s 
)
static

Definition at line 131 of file lspci.c.

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}
void xfree(void *mem)
Definition: uimain.c:758
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
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
#define printf
Definition: freeldr.h:97
GLdouble s
Definition: gl.h:2039
static BOOL lspci_process_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:110

Referenced by lspci_init().

◆ lspci_process_line()

static BOOL lspci_process_line ( RDPCLIENT This,
const char line,
void data 
)
static

Definition at line 110 of file lspci.c.

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}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
RD_BOOL subprocess(char *const argv[], str_handle_lines_t linehandler, void *data)
static BOOL handle_child_line(RDPCLIENT *This, const char *line, void *data)
Definition: lspci.c:45
#define error(str)
Definition: mkdosfs.c:1605

Referenced by lspci_process().

◆ lspci_send()

static void lspci_send ( RDPCLIENT This,
const char output 
)
static

Definition at line 162 of file lspci.c.

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}
STREAM channel_init(VCHANNEL *channel, uint32 length)
Definition: channels.c:69
void channel_send(STREAM s, VCHANNEL *channel)
Definition: channels.c:79
#define s_mark_end(s)
Definition: parse.h:41
#define out_uint8p(s, v, n)
Definition: parse.h:93
GLenum GLsizei len
Definition: glext.h:6722
Definition: parse.h:23

Referenced by handle_child_line(), and lspci_process_line().

Variable Documentation

◆ current_device

pci_device current_device
static

Definition at line 38 of file lspci.c.

Referenced by handle_child_line(), and lspci_process_line().

◆ lspci_channel

VCHANNEL* lspci_channel
static

Definition at line 25 of file lspci.c.

Referenced by lspci_init(), and lspci_send().