Changeset 563d9d0a in mainline
- Timestamp:
- 2011-09-07T10:17:00Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7099861
- Parents:
- 52eead3e
- Location:
- uspace/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/usb.h
r52eead3e r563d9d0a 36 36 #define LIBUSB_USB_H_ 37 37 38 #include <bool.h> 38 39 #include <sys/types.h> 39 40 #include <byteorder.h> … … 130 131 } usb_target_t; 131 132 133 /** Check USB target for allowed values (address and endpoint). 134 * 135 * @param target. 136 * @return True, if values are wihtin limits, false otherwise. 137 */ 138 static inline bool usb_target_is_valid(usb_target_t target) 139 { 140 return !(target.endpoint > 15 || target.endpoint < 0 141 || target.address >= USB11_ADDRESS_MAX || target.address < 0); 142 } 143 132 144 /** Compare USB targets (addresses and endpoints). 133 145 * -
uspace/lib/usbhost/src/endpoint.c
r52eead3e r563d9d0a 89 89 { 90 90 assert(instance); 91 instance->destroy_hook = NULL; 91 92 instance->hc_data.data = NULL; 92 93 instance->hc_data.toggle_get = NULL; -
uspace/lib/usbhost/src/usb_endpoint_manager.c
r52eead3e r563d9d0a 146 146 fibril_condvar_initialize(&instance->change); 147 147 instance->free_bw = available_bandwidth; 148 bool ht =148 const bool ht = 149 149 hash_table_create(&instance->ep_table, BUCKET_COUNT, MAX_KEYS, &op); 150 150 return ht ? EOK : ENOMEM; … … 160 160 { 161 161 assert(ep); 162 size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,162 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 163 163 data_size, ep->max_packet_size); 164 164 assert(instance); 165 166 fibril_mutex_lock(&instance->guard); 167 168 if (bw > instance->free_bw) { 169 fibril_mutex_unlock(&instance->guard); 170 return ENOSPC; 171 } 165 172 166 173 unsigned long key[MAX_KEYS] = 167 174 {ep->address, ep->endpoint, ep->direction}; 168 fibril_mutex_lock(&instance->guard); 169 170 link_t *item = 175 176 const link_t *item = 171 177 hash_table_find(&instance->ep_table, key); 172 178 if (item != NULL) { 173 179 fibril_mutex_unlock(&instance->guard); 174 180 return EEXISTS; 175 }176 177 if (bw > instance->free_bw) {178 fibril_mutex_unlock(&instance->guard);179 return ENOSPC;180 181 } 181 182 … … 211 212 212 213 node_t *node = hash_table_get_instance(item, node_t, link); 213 if (node->ep->active) 214 if (node->ep->active) { 215 fibril_mutex_unlock(&instance->guard); 214 216 return EBUSY; 217 } 215 218 216 219 instance->free_bw += node->bw; … … 230 233 231 234 fibril_mutex_lock(&instance->guard); 232 link_t *item = hash_table_find(&instance->ep_table, key);235 const link_t *item = hash_table_find(&instance->ep_table, key); 233 236 if (item == NULL) { 234 237 fibril_mutex_unlock(&instance->guard); 235 238 return NULL; 236 239 } 237 node_t *node = hash_table_get_instance(item, node_t, link);240 const node_t *node = hash_table_get_instance(item, node_t, link); 238 241 if (bw) 239 242 *bw = node->bw; … … 255 258 { 256 259 assert(instance); 257 if (target.endpoint > 15 || target.endpoint < 0 258 || target.address >= USB11_ADDRESS_MAX || target.address < 0) { 260 if (!usb_target_is_valid(target)) { 259 261 usb_log_error("Invalid data when checking for toggle reset.\n"); 260 262 return; 261 263 } 262 264 265 assert(data); 263 266 switch (data[1]) 264 267 { 265 case 0x01: /* clear feature*/266 /* recipient is endpoint, value is zero (ENDPOINT_STALL) */268 case 0x01: /* Clear Feature -- resets only cleared ep */ 269 /* Recipient is endpoint, value is zero (ENDPOINT_STALL) */ 267 270 if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) { 268 271 /* endpoint number is < 16, thus first byte is enough */ … … 276 279 break; 277 280 278 case 0x9: /* set configuration */279 case 0x11: /* set interface */280 /* target must be device */281 case 0x9: /* Set Configuration */ 282 case 0x11: /* Set Interface */ 283 /* Recipient must be device */ 281 284 if ((data[0] & 0xf) == 0) { 282 285 usb_target_t reset_target =
Note:
See TracChangeset
for help on using the changeset viewer.