#ifndef cp_net_h #define cp_net_h /* Cesar project {{{ * * Copyright (C) 2008 Spidcom * * <<>> * * }}} */ /** * \file cp/sta/mgr/net.h * \brief Network data. * \ingroup cp_sta_mgr * * Get all the data about an AVLN. */ #include "lib/slab.h" #include "cp/cp.h" #include "cp/sta/mgr/sta.h" enum cp_net_network_mode_t { CP_NET_NM_UNCOORDINATED, CP_NET_NM_COORDINATED, CP_NET_NM_CSMA_ONLY, CP_NET_NM_ASSERT }; typedef enum cp_net_network_mode_t cp_net_network_mode_t; enum cp_net_sta_status_t { CP_NET_STA_UNASSOC, CP_NET_STA_ASSOC, CP_NET_STA_NB }; typedef enum cp_net_sta_status_t cp_net_sta_status_t; /** Forward declaration. */ typedef struct cp_net_t cp_net_t; BEGIN_DECLS /** * Initialise the net. * \param ctx the CP context. * \param net the net to initialise. */ void cp_net_init (cp_t *ctx, cp_net_t *net); /** * Uninitialise the net. * \param ctx the module context. * \param the net module. */ void cp_net_uninit (cp_t *ctx, cp_net_t *net); /** * Remove old station which has not been seen for a while. * \param ctx the module context. * \param net the network to garbage. * \param date_ms the current date in milliseconds. * * Remove old station which has not been seen for a while. */ void cp_net_garbage_stations (cp_t *ctx, cp_net_t *net, u32 date_ms); /** * Set the CCo in the Network list. * \param ctx the module context. * \param net the network. * \param tei The Station's TEI which is the CCo. * * Shall update the data bases. */ void cp_net_set_cco (cp_t *ctx, cp_net_t *net, cp_tei_t tei); /** * Set the PCo for this station. * \param ctx the module context. * \param net the network. * \param tei PCo's tei. * * Set the PCo for this network to communicate to another network. */ void cp_net_set_pco (cp_t *ctx, cp_net_t *net, cp_tei_t tei); /** * Get the CCo of this AVLN. * \param ctx the module context. * \param net the network. * \return A reference on the CCo station or NULL if this station is CCo. * The user is responsible to release the reference. */ cp_sta_t * cp_net_get_cco (cp_t *ctx, cp_net_t *net); /** * Get the peer structure of the CCo of this AVLN. * \param ctx the module context. * \param net the network. * \param peer peer structure pointer. * * This is a fatal error if there is no CCo or this station is the CCo. */ void cp_net_get_cco_peer (cp_t *ctx, cp_net_t *net, cp_mme_peer_t *peer); /** * Get the PCo of the AVLN. * \param ctx the module context. * \param net the network. * \return A reference on the PCo station. * * The user is responsible to release the reference. */ cp_sta_t * cp_net_get_pco (cp_t *ctx, cp_net_t *net); /** * Get the peer structure of the PCo of the AVLN. * \param ctx the module context. * \param net the network. * \param peer peer structure pointer. * * This is a fatal error if there is no PCo. */ void cp_net_get_pco_peer (cp_t *ctx, cp_net_t *net, cp_mme_peer_t *peer); /** * Returns the first station of an AVLN. * \param ctx the module context. * \param net the network context. * \param assoc to search in the associated stations or unassociated STAs. * \return the Station with the minimal TEI for the associated stations, the * one with the minimal mac address for the unassociated. * * Returns a reference to the first station of an AVLN. */ cp_sta_t * cp_net_sta_get_first (cp_t *ctx, cp_net_t *net, cp_net_sta_status_t assoc); /** * Get the next station from the AVLN stating by the previous one already * request. * \param ctx the module context. * \param net the network context. * \param prev_sta the previous station requested, whose reference is * released. * \return the next station. * * This function shall be call after get_first. * * Returns a reference to the next station, release a reference to the * previous station. This is done to make this kind of loop easy: * * \code * for (sta = cp_net_get_first (ctx, net, CP_STA_STATE_EXISTS; * sta; sta = cp_net_get_next (ctx, net, sta)) * { * ... * } * \endcode */ cp_sta_t * cp_net_sta_get_next (cp_t *ctx, cp_net_t *net, cp_sta_t *prev_sta); /** * Get the network SNID. * \param ctx the module context. * \param net the network context. * \return The network SNID. */ cp_snid_t cp_net_get_snid (cp_t *ctx, cp_net_t *net); /** * Get the AVLN NID. * \param ctx the module context. * \param net the network context. * \return The network NID. */ cp_nid_t cp_net_get_nid (cp_t *ctx, cp_net_t *net); /** * Set the AVLN slot id and slot usage. * \param ctx the module context. * \param net the network context. * \param slot_id The AVLN Slot id. * \param slot_usage the AVLN slot usage mask */ void cp_net_set_slot_id_and_usage (cp_t *ctx, cp_net_t *net, u8 slot_id, u8 slot_usage); /** * Get the slot id of the network. * \param ctx the module context. * \param net the network context. * \return the slot id of the central beacon. */ u8 cp_net_get_slot_id (cp_t *ctx, cp_net_t *net); /** * Return the slot usage mask of the AVLN read in the central beacon of * the AVLN. * \param ctx the module context. * \param net the network context. * \return The slot usage mask read in the central beacon. * */ u8 cp_net_get_slot_usage_mask (cp_t *ctx, cp_net_t *net); /** * Get the number of station discovered in the AVLN. * \param net the network context. * \return the number of discovered stations. */ u8 cp_net_get_num_discovered_stas (cp_t *ctx, cp_net_t *net); /** * Get the number of station of the AVLN. * \param ctx the module context. * \param net the network context. * \return Return the number of station in the AVLN. * */ u8 cp_net_get_num_stas (cp_t *ctx, cp_net_t *net); /** * Set the current network mode. * \param ctx the module context. * \param net the network context. * \param mode the mode. */ void cp_net_set_nm (cp_t *ctx, cp_net_t *net, cp_net_network_mode_t mode); /** * Get the current network mode. * \param ctx the module context. * \param net the network context. * \return mode the mode. */ cp_net_network_mode_t cp_net_get_nm (cp_t *ctx, cp_net_t *net); /** * Get the status of the network. * \param ctx the context module. * \param net the network context. * \return true if empty, false otherwise. * * This function only check the associated station list in the network. */ bool cp_net_is_empty (cp_t *ctx, cp_net_t *net); /** * Set the UCCo for the AVLN. * \param ctx the CP context. * \param net the net to add the UCCo. * \param sta the station corresponding. */ void cp_net_set_ucco (cp_t *ctx, cp_net_t *net, cp_sta_t *sta); /** * Get the UCCo for the AVLN. * \param ctx the CP context. * \param net the net to add the UCCo. * \return sta the station corresponding. */ cp_sta_t * cp_net_get_ucco (cp_t *ctx, cp_net_t *net); /** * Set the access of the AVLN, * \param ctx the module context. * \param net the network. * \param access the access status. */ void cp_net_set_access (cp_t *ctx, cp_net_t *net, hpav_access_t access); /** * Get the access of the AVLN. * \param ctx the module context. * \param net the network. * \return the access mode of the network. */ hpav_access_t cp_net_get_access (cp_t *ctx, cp_net_t *net); /** * Get the net of a STA. * \param ctx the STA context. * \return the net of the STA. */ cp_net_t * cp_sta_get_net (cp_sta_t *ctx); /** * Get the number of associated stations in the net. * \param ctx the module context. * \param net the network. * \return the number of stations associated. */ uint cp_net_num_sta_associated (cp_t *ctx, cp_net_t *net); END_DECLS #endif /* cp_net_h */