77
88#include "../hid.c"
99
10- static ssize_t parse_max_input_report_size (const char * filename )
10+ struct max_report_sizes {
11+ size_t input ;
12+ size_t output ;
13+ size_t feature ;
14+ };
15+
16+ static int parse_max_input_report_size (const char * filename , struct max_report_sizes * sizes )
1117{
1218 FILE * file = fopen (filename , "r" );
1319 if (file == NULL ) {
@@ -20,16 +26,20 @@ static ssize_t parse_max_input_report_size(const char * filename)
2026 while (fgets (line , sizeof (line ), file ) != NULL ) {
2127 unsigned short temp_ushort ;
2228 if (sscanf (line , "pp_data->caps_info[0]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
23- fclose (file );
24- return (ssize_t )temp_ushort ;
29+ sizes -> input = (size_t )temp_ushort ;
30+ }
31+ if (sscanf (line , "pp_data->caps_info[1]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
32+ sizes -> output = (size_t )temp_ushort ;
33+ }
34+ if (sscanf (line , "pp_data->caps_info[2]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
35+ sizes -> feature = (size_t )temp_ushort ;
2536 }
2637 }
2738 }
2839
29- fprintf (stderr , "Unable to find pp_data->caps_info[0]->ReportByteLength in %s\n" , filename );
3040 fclose (file );
3141
32- return -1 ;
42+ return 0 ;
3343}
3444
3545static bool read_hex_data_from_text_file (const char * filename , unsigned char * data_out , size_t data_size , size_t * actual_read )
@@ -97,19 +107,36 @@ int main(int argc, char* argv[])
97107 return EXIT_FAILURE ;
98108 }
99109
100- ssize_t expected = parse_max_input_report_size ( argv [ 1 ]) ;
101- if (expected < 0 ) {
102- fprintf (stderr , "Unable to expected max input report size from %s\n" , argv [1 ]);
110+ struct max_report_sizes expected ;
111+ if (parse_max_input_report_size ( argv [ 1 ], & expected ) < 0 ) {
112+ fprintf (stderr , "Unable to get expected max report sizes from %s\n" , argv [1 ]);
103113 return EXIT_FAILURE ;
104114 }
105115
106- ssize_t res = (ssize_t )get_max_input_report_size (report_descriptor , report_descriptor_size );
116+ struct max_report_sizes computed = {
117+ .input = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_INPUT ),
118+ .output = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_OUTPUT ),
119+ .feature = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_FEATURE )
120+ };
107121
108- if (res != expected ) {
109- fprintf (stderr , "Failed to properly compute size. Got %zd, expected %zd\n" , res , expected );
110- return EXIT_FAILURE ;
111- } else {
112- printf ("Properly computed size: %zd\n" , res );
113- return EXIT_SUCCESS ;
122+ int ret = EXIT_SUCCESS ;
123+
124+ if (expected .input != computed .input ) {
125+ fprintf (stderr , "Failed to properly compute input size. Got %zu, expected %zu\n" , computed .input , expected .input );
126+ ret = EXIT_FAILURE ;
114127 }
128+ if (expected .output != computed .output ) {
129+ fprintf (stderr , "Failed to properly compute output size. Got %zu, expected %zu\n" , computed .output , expected .output );
130+ ret = EXIT_FAILURE ;
131+ }
132+ if (expected .feature != computed .feature ) {
133+ fprintf (stderr , "Failed to properly compute feature size. Got %zu, expected %zu\n" , computed .feature , expected .feature );
134+ ret = EXIT_FAILURE ;
135+ }
136+
137+ if (ret == EXIT_SUCCESS ) {
138+ printf ("Properly computed sizes: %zu, %zu, %zu\n" , computed .input , computed .output , computed .feature );
139+ }
140+
141+ return ret ;
115142}
0 commit comments