NMSupplicantInterface *
nm_supplicant_interface_new (const char *ifname,
                             gboolean is_wireless,
                             gboolean fast_supported,
                             ApSupport ap_support,
                             gboolean start_now)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;

	g_return_val_if_fail (ifname != NULL, NULL);

	self = g_object_new (NM_TYPE_SUPPLICANT_INTERFACE, NULL);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	priv->dev = g_strdup (ifname);
	priv->is_wireless = is_wireless;
	priv->fast_supported = fast_supported;
	priv->ap_support = ap_support;

	if (start_now)
		interface_add (self, priv->is_wireless);

	return self;
}
NMSupplicantInterface *
nm_supplicant_interface_new (NMSupplicantManager *smgr,
                             const char *ifname,
                             gboolean is_wireless,
                             gboolean start_now)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	guint id;

	g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (smgr), NULL);
	g_return_val_if_fail (ifname != NULL, NULL);

	self = g_object_new (NM_TYPE_SUPPLICANT_INTERFACE, NULL);
	if (self) {
		priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

		priv->smgr = g_object_ref (smgr);
		id = g_signal_connect (priv->smgr,
		                       "notify::" NM_SUPPLICANT_MANAGER_AVAILABLE,
		                       G_CALLBACK (smgr_avail_cb),
		                       self);
		priv->smgr_avail_id = id;

		priv->dev = g_strdup (ifname);
		priv->is_wireless = is_wireless;

		if (start_now)
			interface_add (self, priv->is_wireless);
	}

	return self;
}
Exemple #3
0
List *list_new (int flags) {
    if (! t_list) {
        t_list = obj_new_type(List,List_dispose);
        interface_add(interface_typeof(Iterable),t_list,&list_i);
    }
    List *self = (List*)obj_new_from_type(t_list);
    list_init_(self,flags);
    return self;
}
void
nm_supplicant_interface_set_supplicant_available (NMSupplicantInterface *self,
                                                  gboolean available)
{
	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	if (available) {
		/* This can happen if the supplicant couldn't be activated but
		 * for some reason was started after the activation failure.
		 */
		if (priv->state == NM_SUPPLICANT_INTERFACE_STATE_INIT)
			interface_add (self, priv->is_wireless);
	} else {
		/* The supplicant stopped; so we must tear down the interface */
		set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN);
	}
}
static void
smgr_avail_cb (NMSupplicantManager *smgr,
               GParamSpec *pspec,
               gpointer user_data)
{
	NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data);
	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (user_data);

	if (nm_supplicant_manager_available (smgr)) {
		/* This can happen if the supplicant couldn't be activated but
		 * for some reason was started after the activation failure.
		 */
		if (priv->state == NM_SUPPLICANT_INTERFACE_STATE_INIT)
			interface_add (self, priv->is_wireless);
	} else {
		/* The supplicant stopped; so we must tear down the interface */
		set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN);
	}
}
Exemple #6
0
/**@brief Function for receiving 6LoWPAN module events.
 *
 * @param[in]   p_6lo_interface  Pointer to 6LoWPAN interface.
 * @param[in]   p_6lo_event      Pointer to 6LoWPAN related event.
 *
 * @return      None.
 */
static void ble_6lowpan_evt_handler(iot_interface_t     * p_interface,
                                    ble_6lowpan_event_t * p_6lo_event)
{
    bool                        rx_failure = false;
    uint32_t                    err_code;
    uint32_t                    interface_id;
    iot_pbuffer_t             * p_pbuffer;
    iot_pbuffer_alloc_param_t   pbuff_param;

    IPV6_MUTEX_LOCK();

    IPV6_ENTRY();
    IPV6_TRC("In 6LoWPAN Handler:");

    interface_id = interface_get_by_6lo(p_interface);

    switch (p_6lo_event->event_id)
    {
        case BLE_6LO_EVT_ERROR:
        {
            IPV6_ERR("Got error, with result %08lx", p_6lo_event->event_result);
            break;
        }
        case BLE_6LO_EVT_INTERFACE_ADD:
        {
            IPV6_TRC("New interface established!");

            // Add interface to internal table.
            err_code = interface_add(p_interface, &interface_id);

            if (NRF_SUCCESS == err_code)
            {
                IPV6_TRC("Added new network interface to internal table.");

                err_code = iot_context_manager_table_alloc(p_interface);

                if (err_code == NRF_SUCCESS)
                {
                    IPV6_TRC("Successfully allocated context table!");
                }
                else
                {
                    IPV6_ERR("Failed to allocate context table!");
                }

                // Increase number of up interfaces.
                m_interfaces_count++;

                // Notify application.
                app_notify_interface_add(p_interface);
            }
            else
            {
                IPV6_ERR("Cannot add new interface. Table is full.");
            }

            break;
        }
        case BLE_6LO_EVT_INTERFACE_DELETE:
        {
            IPV6_TRC("Interface disconnected!");

            if (interface_id < IPV6_MAX_INTERFACE)
            {
                IPV6_TRC("Removed network interface.");

                // Notify application.
                app_notify_interface_delete(p_interface);

                err_code = iot_context_manager_table_free(p_interface);

                if (err_code == NRF_SUCCESS)
                {
                    IPV6_TRC("Successfully freed context table!");
                }

                // Decrease number of up interfaces.
                m_interfaces_count--;

                // Remove interface from internal table.
                interface_delete(interface_id);
            }
            break;
        }
        case BLE_6LO_EVT_INTERFACE_DATA_RX:
        {
            IPV6_TRC("Got data with size = %d!",
                     p_6lo_event->event_param.rx_event_param.packet_len);
            IPV6_TRC("Data: ");
            IPV6_DUMP(p_6lo_event->event_param.rx_event_param.p_packet,
                      p_6lo_event->event_param.rx_event_param.packet_len);

            if (interface_id < IPV6_MAX_INTERFACE)
            {
                if (p_6lo_event->event_result == NRF_ERROR_NOT_FOUND)
                {
                    IPV6_ERR("Cannot restore IPv6 addresses!");
                    IPV6_ERR("Source CID = 0x%x, Destination CID = 0x%x",
                             p_6lo_event->event_param.rx_event_param.rx_contexts.src_cntxt_id,
                             p_6lo_event->event_param.rx_event_param.rx_contexts.dest_cntxt_id);

                    // Indicates failure.
                    rx_failure = true;
                    break;
                }

                // Check if packet is for us.
                ipv6_addr_t * p_addr =
                  (ipv6_addr_t *)&p_6lo_event->event_param.rx_event_param.p_packet[DEST_ADDR_OFFSET];

                err_code = addr_check(interface_id, p_addr, true);

                // If no address found - drop message.
                if (err_code != NRF_SUCCESS)
                {
                    IPV6_ERR("Packet received on unknown address!");
                    rx_failure = true;
                    break;
                }

                // Try to allocate pbuffer, with no memory.
                pbuff_param.flags  = PBUFFER_FLAG_NO_MEM_ALLOCATION;
                pbuff_param.type   = RAW_PACKET_TYPE;
                pbuff_param.length = p_6lo_event->event_param.rx_event_param.packet_len;

                // Try to allocate pbuffer for receiving data.
                err_code = iot_pbuffer_allocate(&pbuff_param, &p_pbuffer);

                if (err_code == NRF_SUCCESS)
                {
                    p_pbuffer->p_memory  = p_6lo_event->event_param.rx_event_param.p_packet;
                    p_pbuffer->p_payload = p_pbuffer->p_memory + IPV6_IP_HEADER_SIZE;
                    p_pbuffer->length   -= IPV6_IP_HEADER_SIZE;

                    // Execute multiplexer.
                    err_code = ipv6_input(p_interface, p_pbuffer);

                    if (err_code != NRF_SUCCESS)
                    {
                        IPV6_ERR("Failed while processing packet, error = 0x%08lX!", err_code);
                    }
                }
                else
                {
                    IPV6_ERR("Failed to allocate packet buffer!");
                    rx_failure = true;
                }
            }
            else
            {
                IPV6_ERR("[6LOWPAN]: Got data to unknown interface!");
                rx_failure = true;
            }

            break;
        }
        default:
            break;
    }

    if (rx_failure == true)
    {
        UNUSED_VARIABLE(nrf_free(p_6lo_event->event_param.rx_event_param.p_packet));
    }

    IPV6_EXIT();

    IPV6_MUTEX_UNLOCK();
}
Exemple #7
0
static void init_interfaces() {
    interface_add(interface_typeof(Iterable),t_map,&i_map);
    interface_add(interface_typeof(Accessor),t_map,&i_lookup);
}