Deleted Added
full compact
wps_upnp_ssdp.c (189261) wps_upnp_ssdp.c (209158)
1/*
2 * UPnP SSDP for WPS
3 * Copyright (c) 2000-2003 Intel Corporation
4 * Copyright (c) 2006-2007 Sony Corporation
5 * Copyright (c) 2008-2009 Atheros Communications
6 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
7 *
8 * See wps_upnp.c for more details on licensing and code history.

--- 215 unchanged lines hidden (view full) ---

224
225static void advertisement_state_machine_handler(void *eloop_data,
226 void *user_ctx);
227
228
229/**
230 * advertisement_state_machine_stop - Stop SSDP advertisements
231 * @sm: WPS UPnP state machine from upnp_wps_device_init()
1/*
2 * UPnP SSDP for WPS
3 * Copyright (c) 2000-2003 Intel Corporation
4 * Copyright (c) 2006-2007 Sony Corporation
5 * Copyright (c) 2008-2009 Atheros Communications
6 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
7 *
8 * See wps_upnp.c for more details on licensing and code history.

--- 215 unchanged lines hidden (view full) ---

224
225static void advertisement_state_machine_handler(void *eloop_data,
226 void *user_ctx);
227
228
229/**
230 * advertisement_state_machine_stop - Stop SSDP advertisements
231 * @sm: WPS UPnP state machine from upnp_wps_device_init()
232 * @send_byebye: Send byebye advertisement messages immediately
232 */
233 */
233void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm)
234void advertisement_state_machine_stop(struct upnp_wps_device_sm *sm,
235 int send_byebye)
234{
236{
237 struct advertisement_state_machine *a = &sm->advertisement;
238 int islast = 0;
239 struct wpabuf *msg;
240 struct sockaddr_in dest;
241
235 eloop_cancel_timeout(advertisement_state_machine_handler, NULL, sm);
242 eloop_cancel_timeout(advertisement_state_machine_handler, NULL, sm);
243 if (!send_byebye || sm->multicast_sd < 0)
244 return;
245
246 a->type = ADVERTISE_DOWN;
247 a->state = 0;
248 a->sm = sm;
249
250 os_memset(&dest, 0, sizeof(dest));
251 dest.sin_family = AF_INET;
252 dest.sin_addr.s_addr = inet_addr(UPNP_MULTICAST_ADDRESS);
253 dest.sin_port = htons(UPNP_MULTICAST_PORT);
254
255 while (!islast) {
256 msg = next_advertisement(a, &islast);
257 if (msg == NULL)
258 break;
259 if (sendto(sm->multicast_sd, wpabuf_head(msg), wpabuf_len(msg),
260 0, (struct sockaddr *) &dest, sizeof(dest)) < 0) {
261 wpa_printf(MSG_INFO, "WPS UPnP: Advertisement sendto "
262 "failed: %d (%s)", errno, strerror(errno));
263 }
264 wpabuf_free(msg);
265 a->state++;
266 }
236}
237
238
239static void advertisement_state_machine_handler(void *eloop_data,
240 void *user_ctx)
241{
242 struct upnp_wps_device_sm *sm = user_ctx;
243 struct advertisement_state_machine *a = &sm->advertisement;

--- 69 unchanged lines hidden (view full) ---

313 * @sm: WPS UPnP state machine from upnp_wps_device_init()
314 * Returns: 0 on success, -1 on failure
315 */
316int advertisement_state_machine_start(struct upnp_wps_device_sm *sm)
317{
318 struct advertisement_state_machine *a = &sm->advertisement;
319 int next_timeout_msec;
320
267}
268
269
270static void advertisement_state_machine_handler(void *eloop_data,
271 void *user_ctx)
272{
273 struct upnp_wps_device_sm *sm = user_ctx;
274 struct advertisement_state_machine *a = &sm->advertisement;

--- 69 unchanged lines hidden (view full) ---

344 * @sm: WPS UPnP state machine from upnp_wps_device_init()
345 * Returns: 0 on success, -1 on failure
346 */
347int advertisement_state_machine_start(struct upnp_wps_device_sm *sm)
348{
349 struct advertisement_state_machine *a = &sm->advertisement;
350 int next_timeout_msec;
351
321 advertisement_state_machine_stop(sm);
352 advertisement_state_machine_stop(sm, 0);
322
323 /*
324 * Start out advertising down, this automatically switches
325 * to advertising up which signals our restart.
326 */
327 a->type = ADVERTISE_DOWN;
328 a->state = 0;
329 a->sm = sm;

--- 126 unchanged lines hidden (view full) ---

456 }
457
458 a = os_zalloc(sizeof(*a));
459 if (a == NULL)
460 return;
461 a->type = MSEARCH_REPLY;
462 a->state = 0;
463 a->sm = sm;
353
354 /*
355 * Start out advertising down, this automatically switches
356 * to advertising up which signals our restart.
357 */
358 a->type = ADVERTISE_DOWN;
359 a->state = 0;
360 a->sm = sm;

--- 126 unchanged lines hidden (view full) ---

487 }
488
489 a = os_zalloc(sizeof(*a));
490 if (a == NULL)
491 return;
492 a->type = MSEARCH_REPLY;
493 a->state = 0;
494 a->sm = sm;
464 os_memcpy(&a->client, client, sizeof(client));
495 os_memcpy(&a->client, client, sizeof(*client));
465 /* Wait time depending on MX value */
466 next_timeout_msec = (1000 * mx * (os_random() & 0xFF)) >> 8;
467 next_timeout_sec = next_timeout_msec / 1000;
468 next_timeout_msec = next_timeout_msec % 1000;
469 if (eloop_register_timeout(next_timeout_sec, next_timeout_msec,
470 msearchreply_state_machine_handler, sm,
471 a)) {
472 /* No way to recover (from malloc failure) */

--- 306 unchanged lines hidden (view full) ---

779 * This function assures that the multicast address will be properly
780 * handled by Linux networking code (by a modification to routing tables).
781 * This must be done per network interface. It really only needs to be done
782 * once after booting up, but it does not hurt to call this more frequently
783 * "to be safe".
784 */
785int add_ssdp_network(char *net_if)
786{
496 /* Wait time depending on MX value */
497 next_timeout_msec = (1000 * mx * (os_random() & 0xFF)) >> 8;
498 next_timeout_sec = next_timeout_msec / 1000;
499 next_timeout_msec = next_timeout_msec % 1000;
500 if (eloop_register_timeout(next_timeout_sec, next_timeout_msec,
501 msearchreply_state_machine_handler, sm,
502 a)) {
503 /* No way to recover (from malloc failure) */

--- 306 unchanged lines hidden (view full) ---

810 * This function assures that the multicast address will be properly
811 * handled by Linux networking code (by a modification to routing tables).
812 * This must be done per network interface. It really only needs to be done
813 * once after booting up, but it does not hurt to call this more frequently
814 * "to be safe".
815 */
816int add_ssdp_network(char *net_if)
817{
818#ifdef __linux__
787 int ret = -1;
788 int sock = -1;
789 struct rtentry rt;
790 struct sockaddr_in *sin;
791
792 if (!net_if)
793 goto fail;
794
795 os_memset(&rt, 0, sizeof(rt));
796 sock = socket(AF_INET, SOCK_DGRAM, 0);
797 if (sock < 0)
798 goto fail;
799
800 rt.rt_dev = net_if;
819 int ret = -1;
820 int sock = -1;
821 struct rtentry rt;
822 struct sockaddr_in *sin;
823
824 if (!net_if)
825 goto fail;
826
827 os_memset(&rt, 0, sizeof(rt));
828 sock = socket(AF_INET, SOCK_DGRAM, 0);
829 if (sock < 0)
830 goto fail;
831
832 rt.rt_dev = net_if;
801 sin = (struct sockaddr_in *) &rt.rt_dst;
833 sin = aliasing_hide_typecast(&rt.rt_dst, struct sockaddr_in);
802 sin->sin_family = AF_INET;
803 sin->sin_port = 0;
804 sin->sin_addr.s_addr = inet_addr(SSDP_TARGET);
834 sin->sin_family = AF_INET;
835 sin->sin_port = 0;
836 sin->sin_addr.s_addr = inet_addr(SSDP_TARGET);
805 sin = (struct sockaddr_in *) &rt.rt_genmask;
837 sin = aliasing_hide_typecast(&rt.rt_genmask, struct sockaddr_in);
806 sin->sin_family = AF_INET;
807 sin->sin_port = 0;
808 sin->sin_addr.s_addr = inet_addr(SSDP_NETMASK);
809 rt.rt_flags = RTF_UP;
810 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
811 if (errno == EPERM) {
812 wpa_printf(MSG_DEBUG, "add_ssdp_network: No "
813 "permissions to add routing table entry");

--- 7 unchanged lines hidden (view full) ---

821
822 ret = 0;
823
824fail:
825 if (sock >= 0)
826 close(sock);
827
828 return ret;
838 sin->sin_family = AF_INET;
839 sin->sin_port = 0;
840 sin->sin_addr.s_addr = inet_addr(SSDP_NETMASK);
841 rt.rt_flags = RTF_UP;
842 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
843 if (errno == EPERM) {
844 wpa_printf(MSG_DEBUG, "add_ssdp_network: No "
845 "permissions to add routing table entry");

--- 7 unchanged lines hidden (view full) ---

853
854 ret = 0;
855
856fail:
857 if (sock >= 0)
858 close(sock);
859
860 return ret;
861#else /* __linux__ */
862 return 0;
863#endif /* __linux__ */
829}
830
831
832/**
833 * ssdp_open_multicast - Open socket for sending multicast SSDP messages
834 * @sm: WPS UPnP state machine from upnp_wps_device_init()
835 * Returns: 0 on success, -1 on failure
836 */

--- 50 unchanged lines hidden ---
864}
865
866
867/**
868 * ssdp_open_multicast - Open socket for sending multicast SSDP messages
869 * @sm: WPS UPnP state machine from upnp_wps_device_init()
870 * Returns: 0 on success, -1 on failure
871 */

--- 50 unchanged lines hidden ---