system/core
Revision | f6895c0621ae29a4893ef49f7bf6d8d8be26a1a0 (tree) |
---|---|
Zeit | 2011-11-06 02:26:32 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge branch 'aosp/honeycomb-LTE-release' into honeycomb-mr2-x86
@@ -69,6 +69,7 @@ struct Action | ||
69 | 69 | Action *next; |
70 | 70 | |
71 | 71 | char cmd[64]; |
72 | + const char *prod; | |
72 | 73 | void *data; |
73 | 74 | unsigned size; |
74 | 75 |
@@ -183,6 +184,16 @@ static int cb_check(Action *a, int status, char *resp, int invert) | ||
183 | 184 | return status; |
184 | 185 | } |
185 | 186 | |
187 | + if (a->prod) { | |
188 | + if (strcmp(a->prod, cur_product) != 0) { | |
189 | + double split = now(); | |
190 | + fprintf(stderr,"IGNORE, product is %s required only for %s [%7.3fs]\n", | |
191 | + cur_product, a->prod, (split - a->start)); | |
192 | + a->start = split; | |
193 | + return 0; | |
194 | + } | |
195 | + } | |
196 | + | |
186 | 197 | yes = match(resp, value, count); |
187 | 198 | if (invert) yes = !yes; |
188 | 199 |
@@ -214,10 +225,12 @@ static int cb_reject(Action *a, int status, char *resp) | ||
214 | 225 | return cb_check(a, status, resp, 1); |
215 | 226 | } |
216 | 227 | |
217 | -void fb_queue_require(const char *var, int invert, unsigned nvalues, const char **value) | |
228 | +void fb_queue_require(const char *prod, const char *var, | |
229 | + int invert, unsigned nvalues, const char **value) | |
218 | 230 | { |
219 | 231 | Action *a; |
220 | 232 | a = queue_action(OP_QUERY, "getvar:%s", var); |
233 | + a->prod = prod; | |
221 | 234 | a->data = value; |
222 | 235 | a->size = nvalues; |
223 | 236 | a->msg = mkmsg("checking %s", var); |
@@ -244,6 +257,25 @@ void fb_queue_display(const char *var, const char *prettyname) | ||
244 | 257 | a->func = cb_display; |
245 | 258 | } |
246 | 259 | |
260 | +static int cb_save(Action *a, int status, char *resp) | |
261 | +{ | |
262 | + if (status) { | |
263 | + fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); | |
264 | + return status; | |
265 | + } | |
266 | + strncpy(a->data, resp, a->size); | |
267 | + return 0; | |
268 | +} | |
269 | + | |
270 | +void fb_queue_query_save(const char *var, char *dest, unsigned dest_size) | |
271 | +{ | |
272 | + Action *a; | |
273 | + a = queue_action(OP_QUERY, "getvar:%s", var); | |
274 | + a->data = (void *)dest; | |
275 | + a->size = dest_size; | |
276 | + a->func = cb_save; | |
277 | +} | |
278 | + | |
247 | 279 | static int cb_do_nothing(Action *a, int status, char *resp) |
248 | 280 | { |
249 | 281 | fprintf(stderr,"\n"); |
@@ -42,6 +42,8 @@ | ||
42 | 42 | |
43 | 43 | #include "fastboot.h" |
44 | 44 | |
45 | +char cur_product[FB_RESPONSE_SZ + 1]; | |
46 | + | |
45 | 47 | void bootimg_set_cmdline(boot_img_hdr *h, const char *cmdline); |
46 | 48 | |
47 | 49 | boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, |
@@ -340,6 +342,7 @@ static int setup_requirement_line(char *name) | ||
340 | 342 | { |
341 | 343 | char *val[MAX_OPTIONS]; |
342 | 344 | const char **out; |
345 | + char *prod = NULL; | |
343 | 346 | unsigned n, count; |
344 | 347 | char *x; |
345 | 348 | int invert = 0; |
@@ -350,6 +353,14 @@ static int setup_requirement_line(char *name) | ||
350 | 353 | } else if (!strncmp(name, "require ", 8)) { |
351 | 354 | name += 8; |
352 | 355 | invert = 0; |
356 | + } else if (!strncmp(name, "require-for-product:", 20)) { | |
357 | + // Get the product and point name past it | |
358 | + prod = name + 20; | |
359 | + name = strchr(name, ' '); | |
360 | + if (!name) return -1; | |
361 | + *name = 0; | |
362 | + name += 1; | |
363 | + invert = 0; | |
353 | 364 | } |
354 | 365 | |
355 | 366 | x = strchr(name, '='); |
@@ -381,7 +392,7 @@ static int setup_requirement_line(char *name) | ||
381 | 392 | if (out[n] == 0) return -1; |
382 | 393 | } |
383 | 394 | |
384 | - fb_queue_require(name, invert, n, out); | |
395 | + fb_queue_require(prod, name, invert, n, out); | |
385 | 396 | return 0; |
386 | 397 | } |
387 | 398 |
@@ -432,6 +443,8 @@ void do_update(char *fn) | ||
432 | 443 | |
433 | 444 | queue_info_dump(); |
434 | 445 | |
446 | + fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
447 | + | |
435 | 448 | zdata = load_file(fn, &zsize); |
436 | 449 | if (zdata == 0) die("failed to load '%s'", fn); |
437 | 450 |
@@ -498,6 +511,8 @@ void do_flashall(void) | ||
498 | 511 | |
499 | 512 | queue_info_dump(); |
500 | 513 | |
514 | + fb_queue_query_save("product", cur_product, sizeof(cur_product)); | |
515 | + | |
501 | 516 | fname = find_item("info", product); |
502 | 517 | if (fname == 0) die("cannot find android-info.txt"); |
503 | 518 | data = load_file(fname, &sz); |
@@ -43,8 +43,10 @@ char *fb_get_error(void); | ||
43 | 43 | /* engine.c - high level command queue engine */ |
44 | 44 | void fb_queue_flash(const char *ptn, void *data, unsigned sz);; |
45 | 45 | void fb_queue_erase(const char *ptn); |
46 | -void fb_queue_require(const char *var, int invert, unsigned nvalues, const char **value); | |
46 | +void fb_queue_require(const char *prod, const char *var, int invert, | |
47 | + unsigned nvalues, const char **value); | |
47 | 48 | void fb_queue_display(const char *var, const char *prettyname); |
49 | +void fb_queue_query_save(const char *var, char *dest, unsigned dest_size); | |
48 | 50 | void fb_queue_reboot(void); |
49 | 51 | void fb_queue_command(const char *cmd, const char *msg); |
50 | 52 | void fb_queue_download(const char *name, void *data, unsigned size); |
@@ -54,4 +56,7 @@ int fb_execute_queue(usb_handle *usb); | ||
54 | 56 | /* util stuff */ |
55 | 57 | void die(const char *fmt, ...); |
56 | 58 | |
59 | +/* Current product */ | |
60 | +extern char cur_product[FB_RESPONSE_SZ + 1]; | |
61 | + | |
57 | 62 | #endif |
@@ -34,7 +34,7 @@ extern int ifc_down(const char *name); | ||
34 | 34 | extern int ifc_enable(const char *ifname); |
35 | 35 | extern int ifc_disable(const char *ifname); |
36 | 36 | |
37 | -extern int ifc_reset_connections(const char *ifname); | |
37 | +extern int ifc_reset_connections(const char *ifname, const int reset_mask); | |
38 | 38 | |
39 | 39 | extern int ifc_get_addr(const char *name, in_addr_t *addr); |
40 | 40 | extern int ifc_set_addr(const char *name, in_addr_t addr); |
@@ -279,7 +279,7 @@ int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength, unsigned | ||
279 | 279 | return 0; |
280 | 280 | } |
281 | 281 | |
282 | -int ifc_add_ipv4_route(const char *ifname, struct in_addr dst, int prefix_length, | |
282 | +int ifc_act_on_ipv4_route(int action, const char *ifname, struct in_addr dst, int prefix_length, | |
283 | 283 | struct in_addr gw) |
284 | 284 | { |
285 | 285 | struct rtentry rt; |
@@ -311,7 +311,7 @@ int ifc_add_ipv4_route(const char *ifname, struct in_addr dst, int prefix_length | ||
311 | 311 | return -errno; |
312 | 312 | } |
313 | 313 | |
314 | - result = ioctl(ifc_ctl_sock, SIOCADDRT, &rt); | |
314 | + result = ioctl(ifc_ctl_sock, action, &rt); | |
315 | 315 | if (result < 0) { |
316 | 316 | if (errno == EEXIST) { |
317 | 317 | result = 0; |
@@ -330,17 +330,7 @@ int ifc_create_default_route(const char *name, in_addr_t gw) | ||
330 | 330 | in_dst.s_addr = 0; |
331 | 331 | in_gw.s_addr = gw; |
332 | 332 | |
333 | - return ifc_add_ipv4_route(name, in_dst, 0, in_gw); | |
334 | -} | |
335 | - | |
336 | -int ifc_add_host_route(const char *name, in_addr_t dst) | |
337 | -{ | |
338 | - struct in_addr in_dst, in_gw; | |
339 | - | |
340 | - in_dst.s_addr = dst; | |
341 | - in_gw.s_addr = 0; | |
342 | - | |
343 | - return ifc_add_ipv4_route(name, in_dst, 32, in_gw); | |
333 | + return ifc_act_on_route(SIOCADDRT, name, in_dst, 0, in_gw); | |
344 | 334 | } |
345 | 335 | |
346 | 336 | int ifc_enable(const char *ifname) |
@@ -373,19 +363,46 @@ int ifc_disable(const char *ifname) | ||
373 | 363 | return result; |
374 | 364 | } |
375 | 365 | |
376 | -int ifc_reset_connections(const char *ifname) | |
366 | +#define RESET_IPV4_ADDRESSES 0x01 | |
367 | +#define RESET_IPV6_ADDRESSES 0x02 | |
368 | +#define RESET_ALL_ADDRESSES (RESET_IPV4_ADDRESSES | RESET_IPV6_ADDRESSES) | |
369 | + | |
370 | +int ifc_reset_connections(const char *ifname, const int reset_mask) | |
377 | 371 | { |
378 | 372 | #ifdef HAVE_ANDROID_OS |
379 | - int result; | |
373 | + int result, success; | |
380 | 374 | in_addr_t myaddr; |
381 | 375 | struct ifreq ifr; |
382 | - | |
383 | - ifc_init(); | |
384 | - ifc_get_info(ifname, &myaddr, NULL, NULL); | |
385 | - ifc_init_ifr(ifname, &ifr); | |
386 | - init_sockaddr_in(&ifr.ifr_addr, myaddr); | |
387 | - result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr); | |
388 | - ifc_close(); | |
376 | + struct in6_ifreq ifr6; | |
377 | + | |
378 | + if (reset_mask & RESET_IPV4_ADDRESSES) { | |
379 | + /* IPv4. Clear connections on the IP address. */ | |
380 | + ifc_init(); | |
381 | + ifc_get_info(ifname, &myaddr, NULL, NULL); | |
382 | + ifc_init_ifr(ifname, &ifr); | |
383 | + init_sockaddr_in(&ifr.ifr_addr, myaddr); | |
384 | + result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr); | |
385 | + ifc_close(); | |
386 | + } else { | |
387 | + result = 0; | |
388 | + } | |
389 | + | |
390 | + if (reset_mask & RESET_IPV6_ADDRESSES) { | |
391 | + /* | |
392 | + * IPv6. On Linux, when an interface goes down it loses all its IPv6 | |
393 | + * addresses, so we don't know which connections belonged to that interface | |
394 | + * So we clear all unused IPv6 connections on the device by specifying an | |
395 | + * empty IPv6 address. | |
396 | + */ | |
397 | + ifc_init6(); | |
398 | + // This implicitly specifies an address of ::, i.e., kill all IPv6 sockets. | |
399 | + memset(&ifr6, 0, sizeof(ifr6)); | |
400 | + success = ioctl(ifc_ctl_sock6, SIOCKILLADDR, &ifr6); | |
401 | + if (result == 0) { | |
402 | + result = success; | |
403 | + } | |
404 | + ifc_close6(); | |
405 | + } | |
389 | 406 | |
390 | 407 | return result; |
391 | 408 | #else |
@@ -442,67 +459,6 @@ int ifc_remove_host_routes(const char *name) | ||
442 | 459 | } |
443 | 460 | |
444 | 461 | /* |
445 | - * Return the address of the default gateway | |
446 | - * | |
447 | - * TODO: factor out common code from this and remove_host_routes() | |
448 | - * so that we only scan /proc/net/route in one place. | |
449 | - */ | |
450 | -int ifc_get_default_route(const char *ifname) | |
451 | -{ | |
452 | - char name[64]; | |
453 | - in_addr_t dest, gway, mask; | |
454 | - int flags, refcnt, use, metric, mtu, win, irtt; | |
455 | - int result; | |
456 | - FILE *fp; | |
457 | - | |
458 | - fp = fopen("/proc/net/route", "r"); | |
459 | - if (fp == NULL) | |
460 | - return 0; | |
461 | - /* Skip the header line */ | |
462 | - if (fscanf(fp, "%*[^\n]\n") < 0) { | |
463 | - fclose(fp); | |
464 | - return 0; | |
465 | - } | |
466 | - ifc_init(); | |
467 | - result = 0; | |
468 | - for (;;) { | |
469 | - int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n", | |
470 | - name, &dest, &gway, &flags, &refcnt, &use, &metric, &mask, | |
471 | - &mtu, &win, &irtt); | |
472 | - if (nread != 11) { | |
473 | - break; | |
474 | - } | |
475 | - if ((flags & (RTF_UP|RTF_GATEWAY)) == (RTF_UP|RTF_GATEWAY) | |
476 | - && dest == 0 | |
477 | - && strcmp(ifname, name) == 0) { | |
478 | - result = gway; | |
479 | - break; | |
480 | - } | |
481 | - } | |
482 | - fclose(fp); | |
483 | - ifc_close(); | |
484 | - return result; | |
485 | -} | |
486 | - | |
487 | -/* | |
488 | - * Sets the specified gateway as the default route for the named interface. | |
489 | - */ | |
490 | -int ifc_set_default_route(const char *ifname, in_addr_t gateway) | |
491 | -{ | |
492 | - struct in_addr addr; | |
493 | - int result; | |
494 | - | |
495 | - ifc_init(); | |
496 | - addr.s_addr = gateway; | |
497 | - if ((result = ifc_create_default_route(ifname, gateway)) < 0) { | |
498 | - LOGD("failed to add %s as default route for %s: %s", | |
499 | - inet_ntoa(addr), ifname, strerror(errno)); | |
500 | - } | |
501 | - ifc_close(); | |
502 | - return result; | |
503 | -} | |
504 | - | |
505 | -/* | |
506 | 462 | * Removes the default route for the named interface. |
507 | 463 | */ |
508 | 464 | int ifc_remove_default_route(const char *ifname) |
@@ -565,7 +521,7 @@ ifc_configure(const char *ifname, | ||
565 | 521 | return 0; |
566 | 522 | } |
567 | 523 | |
568 | -int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_length, | |
524 | +int ifc_act_on_ipv6_route(int action, const char *ifname, struct in6_addr dst, int prefix_length, | |
569 | 525 | struct in6_addr gw) |
570 | 526 | { |
571 | 527 | struct in6_rtmsg rtmsg; |
@@ -600,7 +556,7 @@ int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_lengt | ||
600 | 556 | return -errno; |
601 | 557 | } |
602 | 558 | |
603 | - result = ioctl(ifc_ctl_sock6, SIOCADDRT, &rtmsg); | |
559 | + result = ioctl(ifc_ctl_sock6, action, &rtmsg); | |
604 | 560 | if (result < 0) { |
605 | 561 | if (errno == EEXIST) { |
606 | 562 | result = 0; |
@@ -612,8 +568,8 @@ int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_lengt | ||
612 | 568 | return result; |
613 | 569 | } |
614 | 570 | |
615 | -int ifc_add_route(const char *ifname, const char *dst, int prefix_length, | |
616 | - const char *gw) | |
571 | +int ifc_act_on_route(int action, const char *ifname, const char *dst, int prefix_length, | |
572 | + const char *gw) | |
617 | 573 | { |
618 | 574 | int ret = 0; |
619 | 575 | struct sockaddr_in ipv4_dst, ipv4_gw; |
@@ -631,7 +587,7 @@ int ifc_add_route(const char *ifname, const char *dst, int prefix_length, | ||
631 | 587 | return -EINVAL; |
632 | 588 | } |
633 | 589 | |
634 | - if (gw == NULL) { | |
590 | + if (gw == NULL || (strlen(gw) == 0)) { | |
635 | 591 | if (addr_ai->ai_family == AF_INET6) { |
636 | 592 | gw = "::"; |
637 | 593 | } else if (addr_ai->ai_family == AF_INET) { |
@@ -639,6 +595,13 @@ int ifc_add_route(const char *ifname, const char *dst, int prefix_length, | ||
639 | 595 | } |
640 | 596 | } |
641 | 597 | |
598 | + if (((addr_ai->ai_family == AF_INET6) && (prefix_length < 0 || prefix_length > 128)) || | |
599 | + ((addr_ai->ai_family == AF_INET) && (prefix_length < 0 || prefix_length > 32))) { | |
600 | + printerr("ifc_add_route: invalid prefix length"); | |
601 | + freeaddrinfo(addr_ai); | |
602 | + return -EINVAL; | |
603 | + } | |
604 | + | |
642 | 605 | ret = getaddrinfo(gw, NULL, &hints, &gw_ai); |
643 | 606 | if (ret != 0) { |
644 | 607 | printerr("getaddrinfo failed: invalid gateway %s\n", gw); |
@@ -656,13 +619,13 @@ int ifc_add_route(const char *ifname, const char *dst, int prefix_length, | ||
656 | 619 | if (addr_ai->ai_family == AF_INET6) { |
657 | 620 | memcpy(&ipv6_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in6)); |
658 | 621 | memcpy(&ipv6_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in6)); |
659 | - ret = ifc_add_ipv6_route(ifname, ipv6_dst.sin6_addr, prefix_length, | |
660 | - ipv6_gw.sin6_addr); | |
622 | + ret = ifc_act_on_ipv6_route(action, ifname, ipv6_dst.sin6_addr, | |
623 | + prefix_length, ipv6_gw.sin6_addr); | |
661 | 624 | } else if (addr_ai->ai_family == AF_INET) { |
662 | 625 | memcpy(&ipv4_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in)); |
663 | 626 | memcpy(&ipv4_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in)); |
664 | - ret = ifc_add_ipv4_route(ifname, ipv4_dst.sin_addr, prefix_length, | |
665 | - ipv4_gw.sin_addr); | |
627 | + ret = ifc_act_on_ipv4_route(action, ifname, ipv4_dst.sin_addr, | |
628 | + prefix_length, ipv4_gw.sin_addr); | |
666 | 629 | } else { |
667 | 630 | printerr("ifc_add_route: getaddrinfo returned un supported address family %d\n", |
668 | 631 | addr_ai->ai_family); |
@@ -673,3 +636,13 @@ int ifc_add_route(const char *ifname, const char *dst, int prefix_length, | ||
673 | 636 | freeaddrinfo(gw_ai); |
674 | 637 | return ret; |
675 | 638 | } |
639 | + | |
640 | +int ifc_add_route(const char *ifname, const char *dst, int prefix_length, const char *gw) | |
641 | +{ | |
642 | + return ifc_act_on_route(SIOCADDRT, ifname, dst, prefix_length, gw); | |
643 | +} | |
644 | + | |
645 | +int ifc_remove_route(const char *ifname, const char*dst, int prefix_length, const char *gw) | |
646 | +{ | |
647 | + return ifc_act_on_route(SIOCDELRT, ifname, dst, prefix_length, gw); | |
648 | +} |
@@ -377,7 +377,7 @@ service debuggerd /system/bin/debuggerd | ||
377 | 377 | class main |
378 | 378 | |
379 | 379 | service ril-daemon /system/bin/rild |
380 | - class late_start | |
380 | + class main | |
381 | 381 | socket rild stream 660 root radio |
382 | 382 | socket rild-debug stream 660 radio system |
383 | 383 | user root |