@@ -65,32 +65,6 @@ void simulate_firmware_execution(const uint8_t* input)
65
65
66
66
int main (void )
67
67
{
68
- // Establish socket connection with client
69
- int portno = 15423 ;
70
- int sockfd = socket (AF_INET , SOCK_STREAM , 0 );
71
- if (sockfd < 0 ) {
72
- perror ("ERROR opening socket" );
73
- return 1 ;
74
- }
75
- struct sockaddr_in serv_addr ;
76
- serv_addr .sin_family = AF_INET ;
77
- serv_addr .sin_addr .s_addr = INADDR_ANY ;
78
- serv_addr .sin_port = htons (portno );
79
- int serv_addr_len = sizeof (serv_addr );
80
- if (bind (sockfd , (struct sockaddr * )& serv_addr , serv_addr_len ) < 0 ) {
81
- perror ("ERROR binding socket" );
82
- return 1 ;
83
- }
84
- if (listen (sockfd , 50 ) < 0 ) {
85
- perror ("ERROR listening on socket" );
86
- return 1 ;
87
- }
88
- if ((commfd = accept (sockfd , (struct sockaddr * )& serv_addr , (socklen_t * )& serv_addr_len )) < 0 ) {
89
- perror ("accept" );
90
- return 1 ;
91
- }
92
- printf ("Socket connection setup success\n" );
93
-
94
68
// BitBox02 simulation initialization
95
69
usb_processing_init ();
96
70
usb_processing_set_send (usb_processing_hww (), send_usb_message_socket );
@@ -121,26 +95,57 @@ int main(void)
121
95
bitbox02_smarteeprom_init ();
122
96
idle_workflow_blocking ();
123
97
124
- // BitBox02 firmware loop
125
- uint8_t input [BUFFER_SIZE ];
126
- int temp_len ;
98
+ // Establish socket connection with client
99
+ int portno = 15423 ;
100
+ int sockfd = socket (AF_INET , SOCK_STREAM , 0 );
101
+ if (sockfd < 0 ) {
102
+ perror ("ERROR opening socket" );
103
+ return 1 ;
104
+ }
105
+ struct sockaddr_in serv_addr ;
106
+ serv_addr .sin_family = AF_INET ;
107
+ serv_addr .sin_addr .s_addr = INADDR_ANY ;
108
+ serv_addr .sin_port = htons (portno );
109
+ int serv_addr_len = sizeof (serv_addr );
110
+ if (bind (sockfd , (struct sockaddr * )& serv_addr , serv_addr_len ) < 0 ) {
111
+ perror ("ERROR binding socket" );
112
+ return 1 ;
113
+ }
114
+ if (listen (sockfd , 50 ) < 0 ) {
115
+ perror ("ERROR listening on socket" );
116
+ return 1 ;
117
+ }
127
118
while (1 ) {
128
- // Simulator polls for USB messages from client and then processes them
129
- if (!get_usb_message_socket (input )) break ;
130
- simulate_firmware_execution (input );
119
+ if ((commfd = accept (sockfd , (struct sockaddr * )& serv_addr , (socklen_t * )& serv_addr_len )) <
120
+ 0 ) {
121
+ perror ("accept" );
122
+ return 1 ;
123
+ }
124
+ printf ("Socket connection setup success\n" );
125
+
126
+ // BitBox02 firmware loop
127
+ uint8_t input [BUFFER_SIZE ];
128
+ int temp_len ;
129
+ while (1 ) {
130
+ // Simulator polls for USB messages from client and then processes them
131
+ if (!get_usb_message_socket (input )) break ;
132
+ simulate_firmware_execution (input );
131
133
132
- // If the USB message to be sent from firmware is bigger than one packet,
133
- // then the simulator sends the message in multiple packets. Packets use
134
- // HID format, just like the real USB messages.
135
- temp_len = data_len - (USB_HID_REPORT_OUT_SIZE - 7 );
136
- while (temp_len > 0 ) {
137
- // When USB message processing function is called without a new
138
- // input, then it does not consume any packets but it still calls
139
- // the send function to send further USB messages
140
- usb_processing_process (usb_processing_hww ());
141
- temp_len -= (USB_HID_REPORT_OUT_SIZE - 5 );
134
+ // If the USB message to be sent from firmware is bigger than one packet,
135
+ // then the simulator sends the message in multiple packets. Packets use
136
+ // HID format, just like the real USB messages.
137
+ temp_len = data_len - (USB_HID_REPORT_OUT_SIZE - 7 );
138
+ while (temp_len > 0 ) {
139
+ // When USB message processing function is called without a new
140
+ // input, then it does not consume any packets but it still calls
141
+ // the send function to send further USB messages
142
+ usb_processing_process (usb_processing_hww ());
143
+ temp_len -= (USB_HID_REPORT_OUT_SIZE - 5 );
144
+ }
142
145
}
146
+ close (commfd );
147
+ printf ("Socket connection closed\n" );
148
+ printf ("Waiting for new clients, CTRL+C to shut down the simulator\n" );
143
149
}
144
- close (commfd );
145
150
return 0 ;
146
151
}
0 commit comments