The speed is handled at the hardware level, not the software level. The USB system would be unworkable if it allowed programmers to set the connection speed and tried to do things like make a 10M/s connection go 400M/s. I believe that on power up the USB controller can tell the USB devices speed by a voltage level. Each connection speed uses a different resistance to pull a line low and the resulting voltage level tells the controller what the devices speed is, 1, 10 or 400 M/s. If I have the details wrong someone can correct me, but it goes something like that.