Changeset 278fede in mainline
- Timestamp:
- 2014-07-15T00:01:51Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 96e368a
- Parents:
- 07e647a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nic/nic.c
r07e647a r278fede 55 55 { 56 56 printf("syntax:\n"); 57 printf("\t" NAME "\n"); 57 printf("\t" NAME " [<index> <cmd> [<args...>]]\n"); 58 printf("\t<index> is NIC index number reported by the tool\n"); 59 printf("\t<cmd> is:\n"); 60 printf("\taddr <mac_address> - set MAC address\n"); 61 printf("\tspeed <10|100|1000> - set NIC speed\n"); 62 printf("\tduplex <half|full> - set duplex mode\n"); 63 } 64 65 static async_sess_t *get_nic_by_index(size_t i) 66 { 67 int rc; 68 size_t count; 69 char *svc_name; 70 category_id_t nic_cat; 71 service_id_t *nics = NULL; 72 async_sess_t *sess; 73 74 rc = loc_category_get_id("nic", &nic_cat, 0); 75 if (rc != EOK) { 76 printf("Error resolving category 'nic'.\n"); 77 goto error; 78 } 79 80 rc = loc_category_get_svcs(nic_cat, &nics, &count); 81 if (rc != EOK) { 82 printf("Error getting list of NICs.\n"); 83 goto error; 84 } 85 86 rc = loc_service_get_name(nics[i], &svc_name); 87 if (rc != EOK) { 88 printf("Error getting service name.\n"); 89 goto error; 90 } 91 92 printf("Using device: %s\n", svc_name); 93 94 sess = loc_service_connect(EXCHANGE_SERIALIZE, nics[i], 0); 95 if (sess == NULL) { 96 printf("Error connecting to service.\n"); 97 goto error; 98 } 99 100 return sess; 101 error: 102 return NULL; 58 103 } 59 104 … … 67 112 sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 0); 68 113 if (sess == NULL) { 69 printf("Error connecting '%s'.\n", svc_name); 70 rc = EIO; 114 printf("Error connecting to service.\n"); 71 115 goto error; 72 116 } … … 121 165 case NIC_CM_FULL_DUPLEX: return "full-duplex"; 122 166 case NIC_CM_HALF_DUPLEX: return "half-duplex"; 167 case NIC_CM_SIMPLEX: return "simplex"; 123 168 default: assert(false); return NULL; 124 169 } … … 161 206 } 162 207 163 printf("[ Address] [Service Name]\n");208 printf("[Service Name]\n"); 164 209 for (i = 0; i < count; i++) { 165 210 rc = loc_service_get_name(nics[i], &svc_name); … … 180 225 } 181 226 182 printf("%s %s\n", addr_str, svc_name); 227 printf("%d: %s\n", i, svc_name); 228 printf("\tMAC address: %s\n", addr_str); 183 229 printf("\tVendor name: %s\n", 184 230 nic_info.device_info.vendor_name); … … 203 249 } 204 250 251 static int nic_set_speed(int i, char *str) 252 { 253 async_sess_t *sess; 254 uint32_t speed; 255 int oldspeed; 256 nic_channel_mode_t oldduplex; 257 nic_role_t oldrole; 258 int rc; 259 260 rc = str_uint32_t(str, NULL, 10, false, &speed); 261 if (rc != EOK) { 262 printf("Speed must be a numeric value.\n"); 263 return rc; 264 } 265 266 if (speed != 10 && speed != 100 && speed != 1000) { 267 printf("Speed must be one of: 10, 100, 1000.\n"); 268 return EINVAL; 269 } 270 271 sess = get_nic_by_index(i); 272 if (sess == NULL) { 273 printf("Specified NIC doesn't exist or cannot connect to it.\n"); 274 return EINVAL; 275 } 276 277 rc = nic_get_operation_mode(sess, &oldspeed, &oldduplex, &oldrole); 278 if (rc != EOK) { 279 printf("Error getting NIC speed and duplex mode.\n"); 280 return EIO; 281 } 282 283 return nic_set_operation_mode(sess, speed, oldduplex, oldrole); 284 } 285 286 static int nic_set_duplex(int i, char *str) 287 { 288 async_sess_t *sess; 289 int oldspeed; 290 nic_channel_mode_t duplex = NIC_CM_UNKNOWN; 291 nic_channel_mode_t oldduplex; 292 nic_role_t oldrole; 293 int rc; 294 295 if (!str_cmp(str, "half")) 296 duplex = NIC_CM_HALF_DUPLEX; 297 298 if (!str_cmp(str, "full")) 299 duplex = NIC_CM_FULL_DUPLEX; 300 301 if (!str_cmp(str, "simplex")) 302 duplex = NIC_CM_SIMPLEX; 303 304 if (duplex == NIC_CM_UNKNOWN) { 305 printf("Invalid duplex specification.\n"); 306 return EINVAL; 307 } 308 309 sess = get_nic_by_index(i); 310 if (sess == NULL) { 311 printf("Specified NIC doesn't exist or cannot connect to it.\n"); 312 return EINVAL; 313 } 314 315 rc = nic_get_operation_mode(sess, &oldspeed, &oldduplex, &oldrole); 316 if (rc != EOK) { 317 printf("Error getting NIC speed and duplex mode.\n"); 318 return EIO; 319 } 320 321 return nic_set_operation_mode(sess, oldspeed, duplex, oldrole); 322 } 323 324 static int nic_set_addr(int i, char *str) 325 { 326 async_sess_t *sess; 327 nic_address_t addr; 328 int rc, idx; 329 330 sess = get_nic_by_index(i); 331 if (sess == NULL) { 332 printf("Specified NIC doesn't exist or cannot connect to it.\n"); 333 return EINVAL; 334 } 335 336 if (str_size(str) != 17) { 337 printf("Invalid MAC address specified"); 338 return EINVAL; 339 } 340 341 for (idx = 0; idx < 6; idx++) { 342 rc = str_uint8_t(&str[idx * 3], NULL, 16, false, &addr.address[idx]); 343 if (rc != EOK) { 344 printf("Invalid MAC address specified"); 345 return EINVAL; 346 } 347 } 348 349 return nic_set_address(sess, &addr); 350 } 351 205 352 int main(int argc, char *argv[]) 206 353 { 207 354 int rc; 355 uint32_t index; 208 356 209 357 if (argc == 1) { … … 211 359 if (rc != EOK) 212 360 return 1; 361 } else if (argc >= 3) { 362 rc = str_uint32_t(argv[1], NULL, 10, false, &index); 363 if (rc != EOK) { 364 printf(NAME ": Invalid argument.\n"); 365 print_syntax(); 366 return 1; 367 } 368 369 if (!str_cmp(argv[2], "addr")) 370 return nic_set_addr(index, argv[3]); 371 372 if (!str_cmp(argv[2], "speed")) 373 return nic_set_speed(index, argv[3]); 374 375 if (!str_cmp(argv[2], "duplex")) 376 return nic_set_duplex(index, argv[3]); 377 213 378 } else { 214 379 printf(NAME ": Invalid argument.\n");
Note:
See TracChangeset
for help on using the changeset viewer.