Exemplo n.º 1
0
/************************************************************************
* NAME: fnet_init
*
* DESCRIPTION: 
*************************************************************************/
fnet_return_t fnet_init( struct fnet_init_params *init_params )
{
    fnet_return_t result = FNET_ERR;

    if(init_params 
        && (fnet_os_mutex_init() == FNET_OK)
        && (fnet_os_event_init() == FNET_OK))
    {
        fnet_os_mutex_lock();

        if(_fnet_enabled == FNET_FALSE) /* Is enabled already?. */
        {
            if((result = fnet_heap_init(init_params->netheap_ptr, init_params->netheap_size)) == FNET_OK )
            {
                if((result = fnet_stack_init()) == FNET_OK)
                {
                    _fnet_enabled = FNET_TRUE; /* Mark the stack is enabled. */
                }
            }
        }

        fnet_os_mutex_unlock();
    }

    return result;
}
Exemplo n.º 2
0
/************************************************************************
* NAME: fnet_fs_unmount
*
* DESCRIPTION: Unmounts a FS.
*************************************************************************/
fnet_return_t fnet_fs_unmount( const fnet_char_t *mount_name )
{
    fnet_return_t               result = FNET_ERR;
    struct fnet_fs_mount_point  *mount_point;
    struct fnet_fs              *fs;
        
    if(mount_name)
    {
        fnet_os_mutex_lock();
        mount_point = fnet_fs_find_mount(&mount_name);
        if(mount_point)
        {
            fs = mount_point->fs;
            
            if(fs && (fs->operations) && (fs->operations->unmount) )
            {
                fs->operations->unmount(mount_point->arg);    
            }
            
            fnet_memset_zero( mount_point, sizeof(struct fnet_fs_mount_point) );
            result = FNET_OK;
        }
        fnet_os_mutex_unlock();
    }  
    
    return result; 
}
Exemplo n.º 3
0
/************************************************************************
* NAME: fnet_netif_set_default
*
* DESCRIPTION: This function sets the default network interface.
*************************************************************************/
void fnet_netif_set_default( fnet_netif_desc_t netif_desc )
{
    if(netif_desc)
    {
        fnet_os_mutex_lock();
        fnet_netif_default = netif_desc;
        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 4
0
void fnet_netif_set_ip4_addr( fnet_netif_desc_t netif_desc, fnet_ip4_addr_t ipaddr )
{
    fnet_netif_t *netif = (fnet_netif_t *)netif_desc;

    fnet_os_mutex_lock();

    if(netif_desc)
    {
        netif->ip4_addr.address = ipaddr; /* IP address */
        netif->ip4_addr.is_automatic = 0; /* Adress is set manually. */

        if(FNET_IP4_CLASS_A(netif->ip4_addr.address))
        {
            if(netif->ip4_addr.subnetmask == 0)
                netif->ip4_addr.subnetmask = FNET_IP4_CLASS_A_NET;

            netif->ip4_addr.netmask = FNET_IP4_CLASS_A_NET;
        }
        else
        {
            if(FNET_IP4_CLASS_B(netif->ip4_addr.address))
            {
                if(netif->ip4_addr.subnetmask == 0)
                    netif->ip4_addr.subnetmask = FNET_IP4_CLASS_B_NET;

                netif->ip4_addr.netmask = FNET_IP4_CLASS_B_NET;
            }
            else
            {
                if(FNET_IP4_CLASS_C(netif->ip4_addr.address))
                {
                    if(netif->ip4_addr.subnetmask == 0)
                        netif->ip4_addr.subnetmask = FNET_IP4_CLASS_C_NET;

                    netif->ip4_addr.netmask = FNET_IP4_CLASS_C_NET;
                }
                /* else: Is not supported */
            }
        }

        netif->ip4_addr.net = netif->ip4_addr.address & netif->ip4_addr.netmask;             /* Network address.*/
        netif->ip4_addr.subnet = netif->ip4_addr.address & netif->ip4_addr.subnetmask;       /* Network and subnet address.*/

        netif->ip4_addr.netbroadcast = netif->ip4_addr.address | (~netif->ip4_addr.netmask); /* Network broadcast address.*/
        netif->ip4_addr.subnetbroadcast = netif->ip4_addr.address
                                          | (~netif->ip4_addr.subnetmask);                   /* Subnet broadcast address.*/


        if(netif->api->set_addr_notify)
            netif->api->set_addr_notify(netif);
    }

    fnet_os_mutex_unlock();
}
Exemplo n.º 5
0
void fnet_netif_set_ip4_gateway( fnet_netif_desc_t netif_desc, fnet_ip4_addr_t gw )
{
    fnet_netif_t *netif = (fnet_netif_t *)netif_desc;

    if(netif)
    {
        fnet_os_mutex_lock();
        netif->ip4_addr.gateway = gw;
        netif->ip4_addr.is_automatic = 0;
        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 6
0
/************************************************************************
* NAME: fnet_fs_rewinddir
*
* DESCRIPTION: Resets the position of the directory stream.
*************************************************************************/
void fnet_fs_rewinddir( fnet_fs_dir_t dir )
{
    struct fnet_fs_desc * dirp = (struct fnet_fs_desc *) dir;
    
    if(dirp)
    {
        fnet_os_mutex_lock();
        /* Reset current index. */
        dirp->pos = 0U; 
        fnet_os_mutex_unlock();	
    }
}
Exemplo n.º 7
0
/************************************************************************
* NAME: fnet_fs_rewind
*
* DESCRIPTION: Resets the position of the file stream.
*************************************************************************/
void fnet_fs_rewind(FNET_FS_FILE file)
{
    struct fnet_fs_desc * filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        /* Reset current pos. */
        filep->pos = 0; 
        fnet_os_mutex_unlock();	
    }
}
Exemplo n.º 8
0
/************************************************************************
* NAME: fnet_fs_rewind
*
* DESCRIPTION: Resets the position of the file stream.
*************************************************************************/
void fnet_fs_rewind(fnet_fs_file_t file)
{
    struct fnet_fs_desc * filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        /* Reset current pos. */
        filep->pos = 0u; 
        fnet_os_mutex_unlock();	
    }
}
Exemplo n.º 9
0
/************************************************************************
* NAME: fnet_netif_set_ip4_dns
*
* DESCRIPTION: This function sets the DNS IP address.
*************************************************************************/
void fnet_netif_set_ip4_dns( fnet_netif_desc_t netif_desc, fnet_ip4_addr_t dns )
{
    fnet_netif_t *netif = (fnet_netif_t *)netif_desc;

    if(netif)
    {
        fnet_os_mutex_lock();
        netif->ip4_addr.dns = dns;
        netif->ip4_addr.is_automatic = 0;
        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 10
0
/************************************************************************
* NAME: fnet_netif_join_ip6_multicast
*
* DESCRIPTION:
*************************************************************************/
void fnet_netif_join_ip6_multicast ( fnet_netif_desc_t netif_desc, const fnet_ip6_addr_t *multicast_addr )
{
	fnet_netif_t *netif = (fnet_netif_t *)netif_desc;
	
	fnet_os_mutex_lock();
	
	if(netif && netif->api->multicast_join_ip6)
	{
		netif->api->multicast_join_ip6(netif, multicast_addr);
	}
	
	fnet_os_mutex_unlock();	
}
Exemplo n.º 11
0
void fnet_netif_leave_ip4_multicast ( fnet_netif_desc_t netif_desc, fnet_ip4_addr_t multicast_addr )
{
	fnet_netif_t *netif = (fnet_netif_t *)netif_desc;
	
	fnet_os_mutex_lock();
	
	if(netif && netif->api->multicast_leave_ip4)
	{
		netif->api->multicast_leave_ip4(netif, multicast_addr);
	}
	
	fnet_os_mutex_unlock();	
}
Exemplo n.º 12
0
/************************************************************************
* NAME: fnet_release
*
* DESCRIPTION: 
*************************************************************************/
void fnet_release(void)
{
    fnet_os_mutex_lock();

    if(_fnet_enabled)
    {
        fnet_stack_release();
        _fnet_enabled = FNET_FALSE;
    }

    fnet_os_mutex_unlock();

    fnet_os_mutex_release();
}
Exemplo n.º 13
0
/************************************************************************
* NAME: fnet_fs_closedir
*
* DESCRIPTION: Close DIR stream.
*************************************************************************/
fnet_return_t fnet_fs_fclose( fnet_fs_file_t file)
{
    fnet_return_t       result = FNET_ERR;
    struct fnet_fs_desc *filep = (struct fnet_fs_desc *)file;

    if(filep)
    {
        fnet_os_mutex_lock();
        fnet_memset_zero( filep, sizeof(struct fnet_fs_desc) ); /* clear file structure */
        fnet_os_mutex_unlock();	
        result = FNET_OK;	
	}
	return result;
}
Exemplo n.º 14
0
/************************************************************************
* NAME: fnet_fs_closedir
*
* DESCRIPTION: Close DIR stream.
*************************************************************************/
fnet_return_t fnet_fs_closedir( fnet_fs_dir_t dir)
{
    fnet_return_t       result = FNET_ERR;
    struct fnet_fs_desc *dirp = (struct fnet_fs_desc *)dir;

    if(dirp)
    {
        fnet_os_mutex_lock();
        fnet_memset_zero( dirp, sizeof(struct fnet_fs_desc) ); /* clear dir structure */
        fnet_os_mutex_unlock();	
        result = FNET_OK;	
	}
	return result;
}
Exemplo n.º 15
0
/************************************************************************
* NAME: fnet_fs_register
*
* DESCRIPTION: This function registers a FS.
*************************************************************************/
void fnet_fs_register( struct fnet_fs *fs )
{
    if(fs)
    {
        fnet_os_mutex_lock();
        fs->_next = fnet_fs_list;

        if(fs->_next != 0)
            fs->_next->_prev = fs;

        fs->_prev = 0;
        fnet_fs_list = fs;
        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 16
0
void fnet_netif_set_ip4_subnet_mask( fnet_netif_desc_t netif_desc, fnet_ip4_addr_t subnet_mask )
{
    fnet_netif_t *netif = (fnet_netif_t *)netif_desc;

    if(netif)
    {
        fnet_os_mutex_lock();
        netif->ip4_addr.subnetmask = subnet_mask;
        netif->ip4_addr.is_automatic = 0;

        netif->ip4_addr.subnet = netif->ip4_addr.address & netif->ip4_addr.subnetmask; // network and subnet address
        netif->ip4_addr.subnetbroadcast = netif->ip4_addr.address
                                          | (~netif->ip4_addr.subnetmask);     // subnet broadcast address
        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 17
0
/************************************************************************
* NAME: fnet_fs_mount
*
* DESCRIPTION: Mounts a FS.
*************************************************************************/
fnet_return_t fnet_fs_mount( fnet_char_t *fs_name, const fnet_char_t *mount_name, const void *arg )
{
    fnet_return_t   result = FNET_ERR;
    struct          fnet_fs_mount_point *mount_point = 0;
    struct          fnet_fs * fs;
    fnet_index_t    i;
        
    if(fs_name && mount_name)
    {
        fnet_os_mutex_lock();
        fs = fnet_fs_find_name(fs_name);
        if(fs)
        {
            for(i=0U; i< FNET_CFG_FS_MOUNT_MAX; i++)
            {
                if(fnet_fs_mount_list[i].fs == 0)
                {
                    mount_point = &fnet_fs_mount_list[i]; /* found free mount point */
                    break;
                }
            }
            
            if(mount_point) 
            {
                if((fs->operations) && (fs->operations->mount))
                {
                    result = fs->operations->mount(arg);
                }
                else
                {
                    result = FNET_OK;
                }
                
                if(result == FNET_OK) /* Mount is successful */
                {
                    mount_point->arg = arg; /* Fill mount info structure. */
                    mount_point->fs = fs;
                    fnet_strncpy( mount_point->name, mount_name, FNET_CFG_FS_MOUNT_NAME_MAX+1U );    
                }  
            }
        }
        fnet_os_mutex_unlock();
    }  
    
    return result; 
}
Exemplo n.º 18
0
/************************************************************************
* NAME: fnet_fs_unregister
*
* DESCRIPTION: This function unregisters a FS.
*************************************************************************/
void fnet_fs_unregister( struct fnet_fs *fs )
{
    if(fs)
    {
        fnet_os_mutex_lock();

        if(fs->_prev == 0)
            fnet_fs_list = fs->_next;
        else
            fs->_prev->_next = fs->_next;

        if(fs->_next != 0)
            fs->_next->_prev = fs->_prev;

        fnet_os_mutex_unlock();
    }
}
Exemplo n.º 19
0
/************************************************************************
* NAME: fnet_fs_fseek
*
* DESCRIPTION: Change the file position indicator for the specified file.
*************************************************************************/
int fnet_fs_fseek (FNET_FS_FILE file, long offset, int origin)
{
    int result = FNET_ERR;
    struct fnet_fs_desc * filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        if(filep->mount && filep->mount->fs 
            && filep->mount->fs->file_operations
            && filep->mount->fs->file_operations->fseek)
        {
            result = filep->mount->fs->file_operations->fseek(filep, offset, (fnet_fs_seek_origin_t)origin);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;  
}
Exemplo n.º 20
0
/************************************************************************
* NAME: fnet_fs_finfo
*
* DESCRIPTION: Reads file info data.
*************************************************************************/
int fnet_fs_finfo (FNET_FS_FILE file, struct fnet_fs_dirent *info)
{
    int result = FNET_ERR;
    struct fnet_fs_desc *filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        if(filep->mount && filep->mount->fs 
            && filep->mount->fs->file_operations
            && filep->mount->fs->file_operations->finfo)
        {
            result = filep->mount->fs->file_operations->finfo(filep, info);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;
}
Exemplo n.º 21
0
/************************************************************************
* NAME: fnet_fs_readdir
*
* DESCRIPTION: Returns a pointer to a structure representing the directory 
* entry. 
*************************************************************************/
fnet_return_t fnet_fs_readdir(fnet_fs_dir_t dir, struct fnet_fs_dirent* dirent)
{
    fnet_return_t       result = FNET_ERR;
    struct fnet_fs_desc *dirp = (struct fnet_fs_desc *) dir;
    
    if(dirp)
    {
        fnet_os_mutex_lock();
        if((dirp->mount) && (dirp->mount->fs) 
            && (dirp->mount->fs->dir_operations)
            && (dirp->mount->fs->dir_operations->readdir))
        {
            result = dirp->mount->fs->dir_operations->readdir(dirp, dirent);
        }
        fnet_os_mutex_unlock();	
    }
    return result;   
}
Exemplo n.º 22
0
/************************************************************************
* NAME: fnet_fs_fseek
*
* DESCRIPTION: Change the file position indicator for the specified file.
*************************************************************************/
fnet_return_t fnet_fs_fseek (fnet_fs_file_t file, fnet_int32_t offset, fnet_fs_seek_origin_t origin)
{
    fnet_return_t       result = FNET_ERR;
    struct fnet_fs_desc *filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        if((filep->mount) && (filep->mount->fs)
            && (filep->mount->fs->file_operations)
            && (filep->mount->fs->file_operations->fseek))
        {
            result = filep->mount->fs->file_operations->fseek(filep, offset, origin);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;  
}
Exemplo n.º 23
0
/************************************************************************
* NAME: fnet_fs_finfo
*
* DESCRIPTION: Reads file info data.
*************************************************************************/
fnet_return_t fnet_fs_finfo (fnet_fs_file_t file, struct fnet_fs_dirent *dirent)
{
    fnet_return_t       result = FNET_ERR;
    struct fnet_fs_desc *filep = (struct fnet_fs_desc *) file;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        if((filep->mount) && (filep->mount->fs)
            && (filep->mount->fs->file_operations)
            && (filep->mount->fs->file_operations->finfo))
        {
            result = filep->mount->fs->file_operations->finfo(filep, dirent);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;
}
Exemplo n.º 24
0
/************************************************************************
* NAME: fnet_fs_readdir
*
* DESCRIPTION: Returns a pointer to a structure representing the directory 
* entry. 
*************************************************************************/
int fnet_fs_readdir(FNET_FS_DIR dir, struct fnet_fs_dirent* dirent)
{
    int result = FNET_ERR;
    struct fnet_fs_desc * dirp = (struct fnet_fs_desc *) dir;
    
    if(dirp)
    {
        fnet_os_mutex_lock();
        if(dirp->mount && dirp->mount->fs 
            && dirp->mount->fs->dir_operations
            && dirp->mount->fs->dir_operations->readdir)
        {
            result = dirp->mount->fs->dir_operations->readdir(dirp, dirent);
        }
        fnet_os_mutex_unlock();	
    }
    return result;   
}
Exemplo n.º 25
0
/************************************************************************
* NAME: get_fs_fread
*
* DESCRIPTION: 
*************************************************************************/
fnet_size_t fnet_fs_fread(void * buf, fnet_size_t size, fnet_fs_file_t file)
{
    fnet_size_t         result = 0u;
    struct fnet_fs_desc *filep = (struct fnet_fs_desc *) file;
    fnet_size_t         bytes = size;
    
    if(filep && bytes && buf)
    {
        fnet_os_mutex_lock();
        if((filep->mount) && (filep->mount->fs) 
            && (filep->mount->fs->file_operations)
            && (filep->mount->fs->file_operations->fread))
        {
            result = filep->mount->fs->file_operations->fread(filep, buf, bytes);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;   
}
Exemplo n.º 26
0
/************************************************************************
* NAME: get_fs_fread
*
* DESCRIPTION: 
*************************************************************************/
unsigned long fnet_fs_fread(void * buf, unsigned long size, FNET_FS_FILE file)
{
    unsigned long result = 0;
    struct fnet_fs_desc * filep = (struct fnet_fs_desc *) file;
    unsigned long bytes = size;
    
    if(filep && bytes && buf)
    {
        fnet_os_mutex_lock();
        if(filep->mount && filep->mount->fs 
            && filep->mount->fs->file_operations
            && filep->mount->fs->file_operations->fread)
        {
            result = filep->mount->fs->file_operations->fread(filep, buf, bytes);    
        }
        fnet_os_mutex_unlock();	
    }
    return result;   
}
Exemplo n.º 27
0
/************************************************************************
* NAME: net_if_find
*
* DESCRIPTION: Returns a network interface given its name.
*************************************************************************/
fnet_netif_desc_t fnet_netif_get_by_name( char *name )
{
    fnet_netif_t *netif;
    fnet_netif_desc_t result = (fnet_netif_desc_t)FNET_NULL;

    fnet_os_mutex_lock();

    if(name)
        for (netif = fnet_netif_list; netif != 0; netif = netif->next)
        {
            if(fnet_strncmp(name, netif->name, FNET_NETIF_NAMELEN) == 0)
            {
                result = (fnet_netif_desc_t)netif;
                break;
            }
        }

    fnet_os_mutex_unlock();
    return result;
}
Exemplo n.º 28
0
/************************************************************************
* NAME: fnet_fs_find_name
*
* DESCRIPTION: Returns a FS given its name.
*************************************************************************/
struct fnet_fs * fnet_fs_find_name( char *name )
{
    struct fnet_fs *fs;
    struct fnet_fs *result = 0;

    fnet_os_mutex_lock();

    if(name)
        for (fs = fnet_fs_list; fs != 0; fs = fs->_next)
        {
            if(fnet_strcmp(name, fs->name) == 0)
            {
                result = fs;
                break;
            }
        }

    fnet_os_mutex_unlock();
    return result;
}
Exemplo n.º 29
0
/************************************************************************
* NAME: fnet_netif_get_hw_addr
*
* DESCRIPTION: This function reads HW interface address. 
*              (MAC address in case of Ethernet interface)
*************************************************************************/
int fnet_netif_get_hw_addr( fnet_netif_desc_t netif_desc, unsigned char *hw_addr, unsigned int hw_addr_size )
{
    int result;
    fnet_netif_t *netif = (fnet_netif_t *)netif_desc;

    fnet_os_mutex_lock();

    if(netif && hw_addr && hw_addr_size && netif->api
        && (hw_addr_size >= netif->api->hw_addr_size)
        && netif->api->get_hw_addr)
    {        
        result = netif->api->get_hw_addr(netif, hw_addr);
    }
    else
        result = FNET_ERR;

    fnet_os_mutex_unlock();

    return result;
}
Exemplo n.º 30
0
/************************************************************************
* NAME: fnet_fs_fgetc
*
* DESCRIPTION: If successful, fgetc returns the next byte or character from the stream 
*  If unsuccessful, fgetc returns EOF.
*************************************************************************/
int fnet_fs_fgetc(FNET_FS_FILE file)
{
    int result = FNET_FS_EOF;
    struct fnet_fs_desc * filep = (struct fnet_fs_desc *) file;
    char buf;
    
    if(filep)
    {
        fnet_os_mutex_lock();
        if(filep->mount && filep->mount->fs 
            && filep->mount->fs->file_operations
            && filep->mount->fs->file_operations->fread)
        {
            if(filep->mount->fs->file_operations->fread(filep, &buf, 1) != 0)
                result = (unsigned char)buf;
        }
        fnet_os_mutex_unlock();	
    }
    return result;   
}