Example #1
0
/***
 * rt_packet_socket - initialize a packet socket
 */
static int rt_packet_socket(struct rtdm_fd *fd, int protocol)
{
    struct rtsocket *sock = rtdm_fd_to_private(fd);
    int             ret;


    if ((ret = rt_socket_init(fd, protocol)) != 0)
	return ret;

    sock->prot.packet.packet_type.type		= protocol;
    sock->prot.packet.ifindex			= 0;
    sock->prot.packet.packet_type.trylock	= rt_packet_trylock;
    sock->prot.packet.packet_type.unlock        = rt_packet_unlock;

    /* if protocol is non-zero, register the packet type */
    if (protocol != 0) {
	sock->prot.packet.packet_type.handler     = rt_packet_rcv;
	sock->prot.packet.packet_type.err_handler = NULL;

	if ((ret = rtdev_add_pack(&sock->prot.packet.packet_type)) < 0) {
	    rt_socket_cleanup(fd);
	    return ret;
	}
    }

    return 0;
}
Example #2
0
/***
 * rt_packet_socket - initialize a packet socket
 */
int rt_packet_socket(struct rtdm_dev_context *sockctx,
                     rtdm_user_info_t *user_info, int protocol)
{
    struct rtsocket *sock = (struct rtsocket *)&sockctx->dev_private;
    int             ret;


    if ((ret = rt_socket_init(sockctx)) != 0)
        return ret;

    sock->prot.packet.packet_type.type = protocol;
    sock->prot.packet.ifindex          = 0;

    /* if protocol is non-zero, register the packet type */
    if (protocol != 0) {
        sock->prot.packet.packet_type.name        = "PACKET_SOCKET";
        sock->prot.packet.packet_type.handler     = rt_packet_rcv;
        sock->prot.packet.packet_type.err_handler = NULL;

        if ((ret = rtdev_add_pack(&sock->prot.packet.packet_type)) < 0) {
            rt_socket_cleanup(sockctx);
            return ret;
        }
    }

    sock->protocol = protocol;

    return 0;
}
Example #3
0
/***
 *  rt_udp_socket - create a new UDP-Socket
 *  @s: socket
 */
int rt_udp_socket(struct rtdm_dev_context *context,
                  rtdm_user_info_t *user_info)
{
    struct rtsocket *sock = (struct rtsocket *)&context->dev_private;
    int             ret;
    int             i;
    int             index;
    unsigned long   flags;


    if ((ret = rt_socket_init(context)) != 0)
        return ret;

    sock->protocol        = IPPROTO_UDP;
    sock->prot.inet.saddr = INADDR_ANY;
    sock->prot.inet.state = TCP_CLOSE;
#ifdef CONFIG_RTNET_RTDM_SELECT
    sock->wakeup_select   = NULL;
#endif /* CONFIG_RTNET_RTDM_SELECT */

    rtos_spin_lock_irqsave(&udp_socket_base_lock, flags);

    /* enforce maximum number of UDP sockets */
    if (free_ports == 0) {
        rtos_spin_unlock_irqrestore(&udp_socket_base_lock, flags);
        rt_socket_cleanup(context);
        return -EAGAIN;
    }
    free_ports--;

    /* find free auto-port in bitmap */
    for (i = 0; i < sizeof(port_bitmap)/4; i++)
        if (port_bitmap[i] != 0xFFFFFFFF)
            break;
    index = ffz(port_bitmap[i]);
    set_bit(index, &port_bitmap[i]);
    index += i*32;
    sock->prot.inet.reg_index = index;
    sock->prot.inet.sport     = index + auto_port_start;

    /* register UDP socket */
    port_registry[index].sport = sock->prot.inet.sport;
    port_registry[index].saddr = INADDR_ANY;
    port_registry[index].sock  = sock;

    rtos_spin_unlock_irqrestore(&udp_socket_base_lock, flags);

    return 0;
}