OpenLTE 基站相關頭文件:用戶、定時器、基站接口、消息接口

Table of Contents

用戶:LTE_fdd_enb_user.h

用戶管理:LTE_fdd_enb_user_mgr.h

定時器:LTE_fdd_enb_timer.h

定時器管理:LTE_fdd_enb_timer_mgr.h

消息接口:LTE_fdd_enb_msgq.h

基站接口:LTE_fdd_enb_interface.h


用戶:LTE_fdd_enb_user.h

/*******************************************************************************

    Copyright 2013-2017 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_user.h

    Description: Contains all the definitions for the LTE FDD eNodeB
                 user class.

    Revision History
    ----------    -------------    --------------------------------------------
    11/09/2013    Ben Wojtowicz    Created file
    05/04/2014    Ben Wojtowicz    Added radio bearer support.
    06/15/2014    Ben Wojtowicz    Added initialize routine.
    08/03/2014    Ben Wojtowicz    Refactored user identities.
    09/03/2014    Ben Wojtowicz    Added ciphering and integrity algorithm
                                   storing.
    11/01/2014    Ben Wojtowicz    Added more MME support and RRC key storage.
    11/29/2014    Ben Wojtowicz    Added DRB setup/teardown and C-RNTI release
                                   timer support.
    12/16/2014    Ben Wojtowicz    Changed the delayed delete functionality.
    02/15/2015    Ben Wojtowicz    Added clear_rbs and fixed copy_rbs.
    07/25/2015    Ben Wojtowicz    Moved the QoS structure from the RB class to
                                   the user class and got rid of the cached
                                   copy of pusch_mac_pdu.
    12/06/2015    Ben Wojtowicz    Changed the deletion and C-RNTI release
                                   procedures.
    02/13/2016    Ben Wojtowicz    Added an inactivity timer.
    03/12/2016    Ben Wojtowicz    Added H-ARQ support.
    07/29/2017    Ben Wojtowicz    Remove QOS support and fixed UL scheduling.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_USER_H__
#define __LTE_FDD_ENB_USER_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_rb.h"
#include "liblte_phy.h"
#include "liblte_mac.h"
#include "liblte_mme.h"
#include "typedefs.h"
#include <string>

/*******************************************************************************
                              DEFINES
*******************************************************************************/

#define LTE_FDD_ENB_USER_INACTIVITY_TIMER_VALUE_MS 10000

/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/


/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/

typedef struct{
    uint64 imsi;
    uint64 imei;
}LTE_FDD_ENB_USER_ID_STRUCT;

typedef struct{
    uint32 nas_count_ul;
    uint32 nas_count_dl;
    uint8  rand[16];
    uint8  res[8];
    uint8  ck[16];
    uint8  ik[16];
    uint8  autn[16];
    uint8  k_nas_enc[32];
    uint8  k_nas_int[32];
    uint8  k_rrc_enc[32];
    uint8  k_rrc_int[32];
}LTE_FDD_ENB_AUTHENTICATION_VECTOR_STRUCT;

typedef struct{
    LIBLTE_MAC_PDU_STRUCT        mac_pdu;
    LIBLTE_PHY_ALLOCATION_STRUCT alloc;
}LTE_FDD_ENB_HARQ_INFO_STRUCT;

/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

class LTE_fdd_enb_user
{
public:
    // Constructor/Destructor
    LTE_fdd_enb_user();
    ~LTE_fdd_enb_user();

    // Initialize
    void init(void);

    // Identity
    void set_id(LTE_FDD_ENB_USER_ID_STRUCT *identity);
    LTE_FDD_ENB_USER_ID_STRUCT* get_id(void);
    bool is_id_set(void);
    void set_guti(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT *_guti);
    LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT* get_guti(void);
    bool is_guti_set(void);
    void set_temp_id(uint64 id);
    uint64 get_temp_id(void);
    std::string get_imsi_str(void);
    uint64 get_imsi_num(void);
    std::string get_imei_str(void);
    uint64 get_imei_num(void);
    void set_c_rnti(uint16 _c_rnti);
    uint16 get_c_rnti(void);
    bool is_c_rnti_set(void);
    void set_ip_addr(uint32 addr);
    uint32 get_ip_addr(void);
    bool is_ip_addr_set(void);
    void prepare_for_deletion(void);

    // Security
    void set_auth_vec(LTE_FDD_ENB_AUTHENTICATION_VECTOR_STRUCT *av);
    LTE_FDD_ENB_AUTHENTICATION_VECTOR_STRUCT* get_auth_vec(void);
    void increment_nas_count_dl(void);
    void increment_nas_count_ul(void);
    bool is_auth_vec_set(void);

    // Capabilities
    void set_eea_support(uint8 eea, bool support);
    bool get_eea_support(uint8 eea);
    void set_eia_support(uint8 eia, bool support);
    bool get_eia_support(uint8 eia);
    void set_uea_support(uint8 uea, bool support);
    bool get_uea_support(uint8 uea);
    bool is_uea_set(void);
    void set_uia_support(uint8 uia, bool support);
    bool get_uia_support(uint8 uia);
    bool is_uia_set(void);
    void set_gea_support(uint8 gea, bool support);
    bool get_gea_support(uint8 gea);
    bool is_gea_set(void);

    // Radio Bearers
    void get_srb0(LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM setup_srb1(LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM teardown_srb1(void);
    LTE_FDD_ENB_ERROR_ENUM get_srb1(LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM setup_srb2(LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM teardown_srb2(void);
    LTE_FDD_ENB_ERROR_ENUM get_srb2(LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM setup_drb(LTE_FDD_ENB_RB_ENUM drb_id, LTE_fdd_enb_rb **rb);
    LTE_FDD_ENB_ERROR_ENUM teardown_drb(LTE_FDD_ENB_RB_ENUM drb_id);
    LTE_FDD_ENB_ERROR_ENUM get_drb(LTE_FDD_ENB_RB_ENUM drb_id, LTE_fdd_enb_rb **rb);
    void copy_rbs(LTE_fdd_enb_user *user);
    void clear_rbs(void);

    // MME
    void set_emm_cause(uint8 cause);
    uint8 get_emm_cause(void);
    void set_attach_type(uint8 type);
    uint8 get_attach_type(void);
    void set_pdn_type(uint8 type);
    uint8 get_pdn_type(void);
    void set_eps_bearer_id(uint8 id);
    uint8 get_eps_bearer_id(void);
    void set_proc_transaction_id(uint8 id);
    uint8 get_proc_transaction_id(void);
    void set_esm_info_transfer(bool eit);
    bool get_esm_info_transfer(void);
    void set_protocol_cnfg_opts(LIBLTE_MME_PROTOCOL_CONFIG_OPTIONS_STRUCT *pco);
    LIBLTE_MME_PROTOCOL_CONFIG_OPTIONS_STRUCT* get_protocol_cnfg_opts(void);

    // MAC
    bool get_dl_ndi(void);
    void flip_dl_ndi(void);
    bool get_ul_ndi(void);
    void flip_ul_ndi(void);
    void store_harq_info(uint32 pucch_tti, LIBLTE_MAC_PDU_STRUCT *mac_pdu, LIBLTE_PHY_ALLOCATION_STRUCT *alloc);
    void clear_harq_info(uint32 pucch_tti);
    LTE_FDD_ENB_ERROR_ENUM get_harq_info(uint32 pucch_tti, LIBLTE_MAC_PDU_STRUCT *mac_pdu, LIBLTE_PHY_ALLOCATION_STRUCT *alloc);
    void set_ul_buffer_size(uint32 N_bytes_in_buffer);
    void update_ul_buffer_size(uint32 N_bytes_received);
    uint32 get_ul_buffer_size(void);

    // Generic
    void set_N_del_ticks(uint32 N_ticks);
    uint32 get_N_del_ticks(void);
    uint32 get_max_ul_bytes_per_subfn(void);
    uint32 get_max_dl_bytes_per_subfn(void);
    void start_inactivity_timer(uint32 m_seconds);
    void reset_inactivity_timer(uint32 m_seconds);
    void stop_inactivity_timer(void);

private:
    // Identity
    LTE_FDD_ENB_USER_ID_STRUCT           id;
    LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
    uint64                               temp_id;
    uint32                               c_rnti;
    uint32                               ip_addr;
    bool                                 id_set;
    bool                                 guti_set;
    bool                                 c_rnti_set;
    bool                                 ip_addr_set;

    // Security
    LTE_FDD_ENB_AUTHENTICATION_VECTOR_STRUCT auth_vec;
    bool                                     auth_vec_set;

    // Capabilities
    bool eea_support[8];
    bool eia_support[8];
    bool uea_support[8];
    bool uea_set;
    bool uia_support[8];
    bool uia_set;
    bool gea_support[8];
    bool gea_set;

    // Radio Bearers
    LTE_fdd_enb_rb *srb0;
    LTE_fdd_enb_rb *srb1;
    LTE_fdd_enb_rb *srb2;
    LTE_fdd_enb_rb *drb[8];

    // MME
    LIBLTE_MME_PROTOCOL_CONFIG_OPTIONS_STRUCT protocol_cnfg_opts;
    uint8                                     emm_cause;
    uint8                                     attach_type;
    uint8                                     pdn_type;
    uint8                                     eps_bearer_id;
    uint8                                     proc_transaction_id;
    bool                                      eit_flag;

    // MAC
    sem_t                                           harq_buffer_sem;
    std::map<uint32, LTE_FDD_ENB_HARQ_INFO_STRUCT*> harq_buffer;
    uint32                                          ul_buffer_size;
    bool                                            dl_ndi;
    bool                                            ul_ndi;

    // Generic
    void handle_timer_expiry(uint32 timer_id);
    uint32 N_del_ticks;
    uint32 inactivity_timer_id;
};

#endif /* __LTE_FDD_ENB_USER_H__ */

用戶管理:LTE_fdd_enb_user_mgr.h

/*******************************************************************************

    Copyright 2013-2016 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_user_mgr.h

    Description: Contains all the definitions for the LTE FDD eNodeB
                 user manager.

    Revision History
    ----------    -------------    --------------------------------------------
    11/09/2013    Ben Wojtowicz    Created file
    05/04/2014    Ben Wojtowicz    Added C-RNTI timeout timers.
    08/03/2014    Ben Wojtowicz    Refactored add_user.
    11/01/2014    Ben Wojtowicz    Added M-TMSI assignment.
    11/29/2014    Ben Wojtowicz    Refactored C-RNTI assign/release, added
                                   C-RNTI transfer, added more ways to add,
                                   delete, and find users.
    12/16/2014    Ben Wojtowicz    Added delayed user delete functionality.
    12/06/2015    Ben Wojtowicz    Changed boost::mutex to sem_t and changed the
                                   user deletion procedure.
    02/13/2016    Ben Wojtowicz    Added ability to retrieve a string of all
                                   registered users.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_USER_MGR_H__
#define __LTE_FDD_ENB_USER_MGR_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_interface.h"
#include "LTE_fdd_enb_user.h"
#include <string>

/*******************************************************************************
                              DEFINES
*******************************************************************************/


/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/


/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/


/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

class LTE_fdd_enb_user_mgr
{
public:
    // Singleton
    static LTE_fdd_enb_user_mgr* get_instance(void);
    static void cleanup(void);

    // External interface
    LTE_FDD_ENB_ERROR_ENUM assign_c_rnti(LTE_fdd_enb_user *user, uint16 *c_rnti);
    LTE_FDD_ENB_ERROR_ENUM release_c_rnti(uint16 c_rnti);
    LTE_FDD_ENB_ERROR_ENUM transfer_c_rnti(LTE_fdd_enb_user *old_user, LTE_fdd_enb_user *new_user);
    LTE_FDD_ENB_ERROR_ENUM reset_c_rnti_timer(uint16 c_rnti);
    uint32 get_next_m_tmsi(void);
    LTE_FDD_ENB_ERROR_ENUM add_user(LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM find_user(std::string imsi, LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM find_user(uint16 c_rnti, LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM find_user(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT *guti, LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM find_user(LIBLTE_RRC_S_TMSI_STRUCT *s_tmsi, LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM find_user(uint32 ip_addr, LTE_fdd_enb_user **user);
    LTE_FDD_ENB_ERROR_ENUM del_user(LTE_fdd_enb_user *user);
    LTE_FDD_ENB_ERROR_ENUM del_user(std::string imsi);
    LTE_FDD_ENB_ERROR_ENUM del_user(uint16 c_rnti);
    LTE_FDD_ENB_ERROR_ENUM del_user(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT *guti);
    std::string print_all_users(void);

private:
    // Singleton
    static LTE_fdd_enb_user_mgr *instance;
    LTE_fdd_enb_user_mgr();
    ~LTE_fdd_enb_user_mgr();

    // C-RNTI Timer
    void handle_c_rnti_timer_expiry(uint32 timer_id);

    // User storage
    std::list<LTE_fdd_enb_user*>        user_list;
    std::list<LTE_fdd_enb_user*>        delayed_del_user_list;
    std::map<uint16, LTE_fdd_enb_user*> c_rnti_map;
    std::map<uint32, uint16>            timer_id_map_forward;
    std::map<uint16, uint32>            timer_id_map_reverse;
    sem_t                               user_sem;
    sem_t                               c_rnti_sem;
    sem_t                               timer_id_sem;
    uint32                              next_m_tmsi;
    uint16                              next_c_rnti;
};

#endif /* __LTE_FDD_ENB_USER_MGR_H__ */

定時器:LTE_fdd_enb_timer.h

/*******************************************************************************

    Copyright 2014 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_timer.h

    Description: Contains all the definitions for the LTE FDD eNodeB
                 timer class.

    Revision History
    ----------    -------------    --------------------------------------------
    05/04/2014    Ben Wojtowicz    Created file
    06/15/2014    Ben Wojtowicz    Added millisecond resolution and seperated
                                   the callback calling functionality.
    11/29/2014    Ben Wojtowicz    Added timer reset support.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_TIMER_H__
#define __LTE_FDD_ENB_TIMER_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_interface.h"

/*******************************************************************************
                              DEFINES
*******************************************************************************/


/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/


/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/


/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

// Timer callback
class LTE_fdd_enb_timer_cb
{
public:
    typedef void (*FuncType)(void*, uint32);
    LTE_fdd_enb_timer_cb();
    LTE_fdd_enb_timer_cb(FuncType f, void* o);
    void operator()(uint32 id);
private:
    FuncType  func;
    void     *obj;
};
template<class class_type, void (class_type::*Func)(uint32)>
    void LTE_fdd_enb_timer_cb_wrapper(void *o, uint32 id)
{
    return (static_cast<class_type*>(o)->*Func)(id);
}

class LTE_fdd_enb_timer
{
public:
    // Constructor/Destructor
    LTE_fdd_enb_timer(uint32 m_seconds, uint32 _id, LTE_fdd_enb_timer_cb _cb);
    ~LTE_fdd_enb_timer();

    // External interface
    void reset(void);
    void increment(void);
    bool expired(void);
    void call_callback(void);

private:
    // Identity
    LTE_fdd_enb_timer_cb cb;
    uint32               id;
    uint32               expiry_m_seconds;
    uint32               current_m_seconds;
};

#endif /* __LTE_FDD_ENB_TIMER_H__ */

定時器管理:LTE_fdd_enb_timer_mgr.h

/*******************************************************************************

    Copyright 2014-2015 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_timer_mgr.h

    Description: Contains all the definitions for the LTE FDD eNodeB
                 timer manager.

    Revision History
    ----------    -------------    --------------------------------------------
    05/04/2014    Ben Wojtowicz    Created file
    06/15/2014    Ben Wojtowicz    Added millisecond resolution.
    08/03/2014    Ben Wojtowicz    Added an invalid timer id.
    11/29/2014    Ben Wojtowicz    Added timer reset support.
    02/15/2015    Ben Wojtowicz    Moved to new message queue for timer ticks.
    12/06/2015    Ben Wojtowicz    Changed boost::mutex to sem_t.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_TIMER_MGR_H__
#define __LTE_FDD_ENB_TIMER_MGR_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_interface.h"
#include "LTE_fdd_enb_timer.h"
#include "LTE_fdd_enb_msgq.h"

/*******************************************************************************
                              DEFINES
*******************************************************************************/

#define LTE_FDD_ENB_INVALID_TIMER_ID 0xFFFFFFFF

/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/


/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/


/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

class LTE_fdd_enb_timer_mgr
{
public:
    // Singleton
    static LTE_fdd_enb_timer_mgr* get_instance(void);
    static void cleanup(void);

    // Start/Stop
    void start(LTE_fdd_enb_msgq *from_mac, LTE_fdd_enb_interface *iface);
    void stop(void);

    // External Interface
    LTE_FDD_ENB_ERROR_ENUM start_timer(uint32 m_seconds, LTE_fdd_enb_timer_cb cb, uint32 *timer_id);
    LTE_FDD_ENB_ERROR_ENUM stop_timer(uint32 timer_id);
    LTE_FDD_ENB_ERROR_ENUM reset_timer(uint32 timer_id);

private:
    // Singleton
    static LTE_fdd_enb_timer_mgr *instance;
    LTE_fdd_enb_timer_mgr();
    ~LTE_fdd_enb_timer_mgr();

    // Start/Stop
    LTE_fdd_enb_interface *interface;
    sem_t                  start_sem;
    bool                   started;

    // Communication
    void handle_msg(LTE_FDD_ENB_MESSAGE_STRUCT &msg);
    void handle_tick(void);
    LTE_fdd_enb_msgq *msgq_from_mac;

    // Timer Storage
    sem_t                                timer_sem;
    std::map<uint32, LTE_fdd_enb_timer*> timer_map;
    uint32                               next_timer_id;
};

#endif /* __LTE_FDD_ENB_TIMER_MGR_H__ */

消息接口:LTE_fdd_enb_msgq.h

/*******************************************************************************

    Copyright 2013-2017 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_msgq.h

    Description: Contains all the definitions for the LTE FDD eNodeB
                 message queues.

    Revision History
    ----------    -------------    --------------------------------------------
    11/09/2013    Ben Wojtowicz    Created file
    01/18/2014    Ben Wojtowicz    Added the ability to set priorities.
    03/26/2014    Ben Wojtowicz    Added RNTI to PUSCH decode message.
    05/04/2014    Ben Wojtowicz    Added messages for MAC, RLC, PDCP, and RRC
                                   communication.
    06/15/2014    Ben Wojtowicz    Added MME<->RRC messages.
    08/03/2014    Ben Wojtowicz    Added RRC command messages.
    11/01/2014    Ben Wojtowicz    Added RRC security command, RRC SRB2 setup
                                   command, and RRC command response messages.
    11/29/2014    Ben Wojtowicz    Added IP gateway communication messages.
    02/15/2015    Ben Wojtowicz    Moving to new message queue with semaphores
                                   and circular buffers and added a timer tick
                                   message.
    03/15/2015    Ben Wojtowicz    Added a mutex to the circular buffer.
    07/25/2015    Ben Wojtowicz    Combined the DL and UL schedule messages into
                                   a single PHY schedule message.
    12/06/2015    Ben Wojtowicz    Changed boost::mutex and
                                   boost::interprocess::interprocess_semaphore
                                   to sem_t.
    03/12/2016    Ben Wojtowicz    Added PUCCH support.
    07/29/2017    Ben Wojtowicz    Added SR Support.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_MSGQ_H__
#define __LTE_FDD_ENB_MSGQ_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_user.h"
#include "liblte_rrc.h"
#include "liblte_phy.h"
#include <boost/circular_buffer.hpp>
#include <string>

/*******************************************************************************
                              DEFINES
*******************************************************************************/

#define LTE_FDD_ENB_N_SIB_ALLOCS      7
#define LTE_FDD_ENB_N_PUCCH_PER_SUBFR 12

/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/


/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/

typedef enum{
    // Generic Messages
    LTE_FDD_ENB_MESSAGE_TYPE_KILL = 0,

    // MAC -> PHY Messages
    LTE_FDD_ENB_MESSAGE_TYPE_PHY_SCHEDULE,

    // PHY -> MAC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_READY_TO_SEND,
    LTE_FDD_ENB_MESSAGE_TYPE_PRACH_DECODE,
    LTE_FDD_ENB_MESSAGE_TYPE_PUCCH_DECODE,
    LTE_FDD_ENB_MESSAGE_TYPE_PUSCH_DECODE,

    // RLC -> MAC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_MAC_SDU_READY,

    // MAC -> RLC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_RLC_PDU_READY,

    // MAC -> TIMER Messages
    LTE_FDD_ENB_MESSAGE_TYPE_TIMER_TICK,

    // PDCP -> RLC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_RLC_SDU_READY,

    // RLC -> PDCP Messages
    LTE_FDD_ENB_MESSAGE_TYPE_PDCP_PDU_READY,

    // RRC -> PDCP Messages
    LTE_FDD_ENB_MESSAGE_TYPE_PDCP_SDU_READY,

    // PDCP -> RRC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_RRC_PDU_READY,

    // MME -> RRC Messages
    LTE_FDD_ENB_MESSAGE_TYPE_RRC_NAS_MSG_READY,
    LTE_FDD_ENB_MESSAGE_TYPE_RRC_CMD_READY,

    // RRC -> MME Messages
    LTE_FDD_ENB_MESSAGE_TYPE_MME_NAS_MSG_READY,
    LTE_FDD_ENB_MESSAGE_TYPE_MME_RRC_CMD_RESP,

    // GW -> PDCP Messages
    LTE_FDD_ENB_MESSAGE_TYPE_PDCP_DATA_SDU_READY,

    // PDCP -> GW Messages
    LTE_FDD_ENB_MESSAGE_TYPE_GW_DATA_READY,

    LTE_FDD_ENB_MESSAGE_TYPE_N_ITEMS,
}LTE_FDD_ENB_MESSAGE_TYPE_ENUM;
static const char LTE_fdd_enb_message_type_text[LTE_FDD_ENB_MESSAGE_TYPE_N_ITEMS][100] = {"Kill",
                                                                                          "PHY schedule",
                                                                                          "Ready to send",
                                                                                          "PRACH decode",
                                                                                          "PUCCH decode",
                                                                                          "PUSCH decode",
                                                                                          "MAC sdu ready",
                                                                                          "RLC pdu ready",
                                                                                          "Timer tick",
                                                                                          "RLC sdu ready",
                                                                                          "PDCP pdu ready",
                                                                                          "PDCP sdu ready",
                                                                                          "RRC pdu ready",
                                                                                          "RRC NAS message ready",
                                                                                          "RRC command ready",
                                                                                          "MME NAS message ready",
                                                                                          "MME RRC command response",
                                                                                          "PDCP data sdu ready",
                                                                                          "GW data ready"};

typedef enum{
    LTE_FDD_ENB_DEST_LAYER_PHY = 0,
    LTE_FDD_ENB_DEST_LAYER_MAC,
    LTE_FDD_ENB_DEST_LAYER_RLC,
    LTE_FDD_ENB_DEST_LAYER_PDCP,
    LTE_FDD_ENB_DEST_LAYER_RRC,
    LTE_FDD_ENB_DEST_LAYER_MME,
    LTE_FDD_ENB_DEST_LAYER_GW,
    LTE_FDD_ENB_DEST_LAYER_TIMER_MGR,
    LTE_FDD_ENB_DEST_LAYER_ANY,
    LTE_FDD_ENB_DEST_LAYER_N_ITEMS,
}LTE_FDD_ENB_DEST_LAYER_ENUM;
static const char LTE_fdd_enb_dest_layer_text[LTE_FDD_ENB_DEST_LAYER_N_ITEMS][100] = {"PHY",
                                                                                      "MAC",
                                                                                      "RLC",
                                                                                      "PDCP",
                                                                                      "RRC",
                                                                                      "MME",
                                                                                      "GW",
                                                                                      "TIMER_MGR",
                                                                                      "ANY"};

// Generic Messages

// MAC -> PHY Messages
typedef struct{
    LIBLTE_PHY_PDCCH_STRUCT dl_allocations;
    LIBLTE_PHY_PDCCH_STRUCT ul_allocations;
    uint32                  N_avail_prbs;
    uint32                  N_sched_prbs;
    uint32                  current_tti;
}LTE_FDD_ENB_DL_SCHEDULE_MSG_STRUCT;
typedef enum{
    LTE_FDD_ENB_PUCCH_TYPE_ACK_NACK = 0,
    LTE_FDD_ENB_PUCCH_TYPE_SR,
    LTE_FDD_ENB_PUCCH_TYPE_N_ITEMS,
}LTE_FDD_ENB_PUCCH_TYPE_ENUM;
static const char LTE_fdd_enb_pucch_type_text[LTE_FDD_ENB_PUCCH_TYPE_N_ITEMS][100] = {"ACK_NACK",
                                                                                      "SR"};
typedef struct{
    LTE_FDD_ENB_PUCCH_TYPE_ENUM type;
    uint32                      n_1_p_pucch;
    uint16                      rnti;
    bool                        decode;
}LTE_FDD_ENB_PUCCH_STRUCT;
typedef struct{
    LIBLTE_PHY_PDCCH_STRUCT  decodes;
    LTE_FDD_ENB_PUCCH_STRUCT pucch[LTE_FDD_ENB_N_PUCCH_PER_SUBFR];
    uint32                   N_avail_prbs;
    uint32                   N_sched_prbs;
    uint32                   current_tti;
    uint32                   N_pucch;
    uint8                    next_prb;
}LTE_FDD_ENB_UL_SCHEDULE_MSG_STRUCT;
typedef struct{
    LTE_FDD_ENB_DL_SCHEDULE_MSG_STRUCT dl_sched;
    LTE_FDD_ENB_UL_SCHEDULE_MSG_STRUCT ul_sched;
}LTE_FDD_ENB_PHY_SCHEDULE_MSG_STRUCT;

// PHY -> MAC Messages
typedef struct{
    uint32 dl_current_tti;
    uint32 ul_current_tti;
    bool   late;
}LTE_FDD_ENB_READY_TO_SEND_MSG_STRUCT;
typedef struct{
    uint32 current_tti;
    uint32 timing_adv[64];
    uint32 preamble[64];
    uint32 num_preambles;
}LTE_FDD_ENB_PRACH_DECODE_MSG_STRUCT;
typedef struct{
    LIBLTE_BIT_MSG_STRUCT       msg;
    LTE_FDD_ENB_PUCCH_TYPE_ENUM type;
    uint32                      current_tti;
    uint16                      rnti;
}LTE_FDD_ENB_PUCCH_DECODE_MSG_STRUCT;
typedef struct{
    LIBLTE_BIT_MSG_STRUCT msg;
    uint32                current_tti;
    uint16                rnti;
}LTE_FDD_ENB_PUSCH_DECODE_MSG_STRUCT;

// RLC -> MAC Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_MAC_SDU_READY_MSG_STRUCT;

// MAC -> RLC Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_RLC_PDU_READY_MSG_STRUCT;

// MAC -> TIMER Messages
typedef struct{
    uint32 tick;
}LTE_FDD_ENB_TIMER_TICK_MSG_STRUCT;

// PDCP -> RLC Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_RLC_SDU_READY_MSG_STRUCT;

// RLC -> PDCP Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_PDCP_PDU_READY_MSG_STRUCT;

// RRC -> PDCP Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_PDCP_SDU_READY_MSG_STRUCT;

// PDCP -> RRC Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_RRC_PDU_READY_MSG_STRUCT;

// MME -> RRC Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_RRC_NAS_MSG_READY_MSG_STRUCT;
typedef enum{
    LTE_FDD_ENB_RRC_CMD_RELEASE = 0,
    LTE_FDD_ENB_RRC_CMD_SECURITY,
    LTE_FDD_ENB_RRC_CMD_SETUP_DEF_DRB,
    LTE_FDD_ENB_RRC_CMD_SETUP_DED_DRB,
    LTE_FDD_ENB_RRC_CMD_N_ITEMS,
}LTE_FDD_ENB_RRC_CMD_ENUM;
static const char LTE_fdd_enb_rrc_cmd_text[LTE_FDD_ENB_RRC_CMD_N_ITEMS][20] = {"Release",
                                                                               "Security",
                                                                               "Setup Default DRB",
                                                                               "Setup Dedicated DRB"};
typedef struct{
    LTE_fdd_enb_user         *user;
    LTE_fdd_enb_rb           *rb;
    LTE_FDD_ENB_RRC_CMD_ENUM  cmd;
}LTE_FDD_ENB_RRC_CMD_READY_MSG_STRUCT;

// RRC -> MME Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_MME_NAS_MSG_READY_MSG_STRUCT;
typedef enum{
    LTE_FDD_ENB_MME_RRC_CMD_RESP_SECURITY = 0,
    LTE_FDD_ENB_MME_RRC_CMD_RESP_N_ITEMS,
}LTE_FDD_ENB_MME_RRC_CMD_RESP_ENUM;
static const char LTE_fdd_enb_mme_rrc_cmd_resp_text[LTE_FDD_ENB_MME_RRC_CMD_RESP_N_ITEMS][20] = {"Security"};
typedef struct{
    LTE_fdd_enb_user                  *user;
    LTE_fdd_enb_rb                    *rb;
    LTE_FDD_ENB_MME_RRC_CMD_RESP_ENUM  cmd_resp;
}LTE_FDD_ENB_MME_RRC_CMD_RESP_MSG_STRUCT;

// GW -> PDCP Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_PDCP_DATA_SDU_READY_MSG_STRUCT;

// PDCP -> GW Messages
typedef struct{
    LTE_fdd_enb_user *user;
    LTE_fdd_enb_rb   *rb;
}LTE_FDD_ENB_GW_DATA_READY_MSG_STRUCT;

typedef union{
    // Generic Messages

    // MAC -> PHY Messages
    LTE_FDD_ENB_PHY_SCHEDULE_MSG_STRUCT phy_schedule;

    // PHY -> MAC Messages
    LTE_FDD_ENB_READY_TO_SEND_MSG_STRUCT ready_to_send;
    LTE_FDD_ENB_PRACH_DECODE_MSG_STRUCT  prach_decode;
    LTE_FDD_ENB_PUCCH_DECODE_MSG_STRUCT  pucch_decode;
    LTE_FDD_ENB_PUSCH_DECODE_MSG_STRUCT  pusch_decode;

    // RLC -> MAC Messages
    LTE_FDD_ENB_MAC_SDU_READY_MSG_STRUCT mac_sdu_ready;

    // MAC -> RLC Messages
    LTE_FDD_ENB_RLC_PDU_READY_MSG_STRUCT rlc_pdu_ready;

    // MAC -> TIMER Messages
    LTE_FDD_ENB_TIMER_TICK_MSG_STRUCT timer_tick;

    // PDCP -> RLC Messages
    LTE_FDD_ENB_RLC_SDU_READY_MSG_STRUCT rlc_sdu_ready;

    // RLC -> PDCP Messages
    LTE_FDD_ENB_PDCP_PDU_READY_MSG_STRUCT pdcp_pdu_ready;

    // RRC -> PDCP Messages
    LTE_FDD_ENB_PDCP_SDU_READY_MSG_STRUCT pdcp_sdu_ready;

    // PDCP -> RRC Messages
    LTE_FDD_ENB_RRC_PDU_READY_MSG_STRUCT rrc_pdu_ready;

    // MME -> RRC Messages
    LTE_FDD_ENB_RRC_NAS_MSG_READY_MSG_STRUCT rrc_nas_msg_ready;
    LTE_FDD_ENB_RRC_CMD_READY_MSG_STRUCT     rrc_cmd_ready;

    // RRC -> MME Messages
    LTE_FDD_ENB_MME_NAS_MSG_READY_MSG_STRUCT mme_nas_msg_ready;
    LTE_FDD_ENB_MME_RRC_CMD_RESP_MSG_STRUCT  mme_rrc_cmd_resp;

    // GW -> PDCP Messages
    LTE_FDD_ENB_PDCP_DATA_SDU_READY_MSG_STRUCT pdcp_data_sdu_ready;

    // PDCP -> GW Messages
    LTE_FDD_ENB_GW_DATA_READY_MSG_STRUCT gw_data_ready;
}LTE_FDD_ENB_MESSAGE_UNION;

typedef struct{
    LTE_FDD_ENB_MESSAGE_TYPE_ENUM type;
    LTE_FDD_ENB_DEST_LAYER_ENUM   dest_layer;
    LTE_FDD_ENB_MESSAGE_UNION     msg;
}LTE_FDD_ENB_MESSAGE_STRUCT;

/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

// Message queue callback
class LTE_fdd_enb_msgq_cb
{
public:
    typedef void (*FuncType)(void*, LTE_FDD_ENB_MESSAGE_STRUCT&);
    LTE_fdd_enb_msgq_cb();
    LTE_fdd_enb_msgq_cb(FuncType f, void* o);
    void operator()(LTE_FDD_ENB_MESSAGE_STRUCT &msg);
private:
    FuncType  func;
    void     *obj;
};
template<class class_type, void (class_type::*Func)(LTE_FDD_ENB_MESSAGE_STRUCT&)>
    void LTE_fdd_enb_msgq_cb_wrapper(void *o, LTE_FDD_ENB_MESSAGE_STRUCT &msg)
{
    return (static_cast<class_type*>(o)->*Func)(msg);
}

class LTE_fdd_enb_msgq
{
public:
    LTE_fdd_enb_msgq(std::string _msgq_name);
    ~LTE_fdd_enb_msgq();

    // Setup
    void attach_rx(LTE_fdd_enb_msgq_cb cb);
    void attach_rx(LTE_fdd_enb_msgq_cb cb, uint32 _prio);

    // Send/Receive
    void send(LTE_FDD_ENB_MESSAGE_TYPE_ENUM  type,
              LTE_FDD_ENB_DEST_LAYER_ENUM    dest_layer,
              LTE_FDD_ENB_MESSAGE_UNION     *msg_content,
              uint32                         msg_content_size);
    void send(LTE_FDD_ENB_MESSAGE_TYPE_ENUM       type,
              LTE_FDD_ENB_DL_SCHEDULE_MSG_STRUCT *dl_sched,
              LTE_FDD_ENB_UL_SCHEDULE_MSG_STRUCT *ul_sched);
    void send(LTE_FDD_ENB_MESSAGE_STRUCT &msg);

private:
    // Send/Receive
    static void* receive_thread(void *inputs);

    // Variables
    LTE_fdd_enb_msgq_cb                                 callback;
    sem_t                                               sync_sem;
    sem_t                                               msg_sem;
    boost::circular_buffer<LTE_FDD_ENB_MESSAGE_STRUCT> *circ_buf;
    std::string                                         msgq_name;
    pthread_t                                           rx_thread;
    uint32                                              prio;
    bool                                                rx_setup;
};

#endif /* __LTE_FDD_ENB_MSGQ_H__ */

基站接口:LTE_fdd_enb_interface.h

/*******************************************************************************

    Copyright 2013-2017 Ben Wojtowicz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************

    File: LTE_fdd_enb_interface.h

    Description: Contains all the definitions for the LTE FDD eNodeB interface.

    Revision History
    ----------    -------------    --------------------------------------------
    11/09/2013    Ben Wojtowicz    Created file
    01/18/2014    Ben Wojtowicz    Added dynamic variables and added level to
                                   debug prints.
    03/26/2014    Ben Wojtowicz    Using the latest LTE library.
    04/12/2014    Ben Wojtowicz    Pulled in a patch from Max Suraev for more
                                   descriptive start failures.
    05/04/2014    Ben Wojtowicz    Added PCAP support and more error types.
    06/15/2014    Ben Wojtowicz    Added new error causes, ... support for info
                                   messages, and using the latest LTE library.
    07/22/2014    Ben Wojtowicz    Added clock source as a configurable
                                   parameter.
    08/03/2014    Ben Wojtowicz    Added HSS support.
    09/03/2014    Ben Wojtowicz    Added read only parameters for UL EARFCN,
                                   DL center frequency and UL center frequency.
    11/01/2014    Ben Wojtowicz    Added parameters for IP address assignment,
                                   DNS address, config file, and user file.
    11/29/2014    Ben Wojtowicz    Added support for the IP gateway.
    02/15/2015    Ben Wojtowicz    Moved to new message queue, added IP pcap
                                   support, and put error enum into common hdr.
    03/11/2015    Ben Wojtowicz    Made a common routine for formatting time.
    07/25/2015    Ben Wojtowicz    Made tx_gain and rx_gain into config file
                                   tracked parameters.
    12/06/2015    Ben Wojtowicz    Changed boost::mutex to sem_t.
    02/13/2016    Ben Wojtowicz    Added a command to print all registered
                                   users.
    07/29/2017    Ben Wojtowicz    Added input parameters for direct IPC to a UE
                                   and using the latest tools library.

*******************************************************************************/

#ifndef __LTE_FDD_ENB_INTERFACE_H__
#define __LTE_FDD_ENB_INTERFACE_H__

/*******************************************************************************
                              INCLUDES
*******************************************************************************/

#include "LTE_fdd_enb_common.h"
#include "LTE_fdd_enb_msgq.h"
#include "liblte_common.h"
#include "libtools_socket_wrap.h"
#include <string>

/*******************************************************************************
                              DEFINES
*******************************************************************************/

#define LTE_FDD_ENB_DEFAULT_CTRL_PORT 30000
#define LTE_FDD_ENB_DEBUG_PORT_OFFSET 1

/*******************************************************************************
                              FORWARD DECLARATIONS
*******************************************************************************/

class LTE_fdd_enb_pdcp;
class LTE_fdd_enb_mme;
class LTE_fdd_enb_gw;

/*******************************************************************************
                              TYPEDEFS
*******************************************************************************/

typedef enum{
    LTE_FDD_ENB_DEBUG_TYPE_ERROR = 0,
    LTE_FDD_ENB_DEBUG_TYPE_WARNING,
    LTE_FDD_ENB_DEBUG_TYPE_INFO,
    LTE_FDD_ENB_DEBUG_TYPE_DEBUG,
    LTE_FDD_ENB_DEBUG_TYPE_N_ITEMS,
}LTE_FDD_ENB_DEBUG_TYPE_ENUM;
static const char LTE_fdd_enb_debug_type_text[LTE_FDD_ENB_DEBUG_TYPE_N_ITEMS][100] = {"error",
                                                                                      "warning",
                                                                                      "info",
                                                                                      "debug"};

typedef enum{
    LTE_FDD_ENB_DEBUG_LEVEL_RADIO = 0,
    LTE_FDD_ENB_DEBUG_LEVEL_PHY,
    LTE_FDD_ENB_DEBUG_LEVEL_MAC,
    LTE_FDD_ENB_DEBUG_LEVEL_RLC,
    LTE_FDD_ENB_DEBUG_LEVEL_PDCP,
    LTE_FDD_ENB_DEBUG_LEVEL_RRC,
    LTE_FDD_ENB_DEBUG_LEVEL_MME,
    LTE_FDD_ENB_DEBUG_LEVEL_GW,
    LTE_FDD_ENB_DEBUG_LEVEL_USER,
    LTE_FDD_ENB_DEBUG_LEVEL_RB,
    LTE_FDD_ENB_DEBUG_LEVEL_TIMER,
    LTE_FDD_ENB_DEBUG_LEVEL_IFACE,
    LTE_FDD_ENB_DEBUG_LEVEL_MSGQ,
    LTE_FDD_ENB_DEBUG_LEVEL_N_ITEMS,
}LTE_FDD_ENB_DEBUG_LEVEL_ENUM;
static const char LTE_fdd_enb_debug_level_text[LTE_FDD_ENB_DEBUG_LEVEL_N_ITEMS][100] = {"radio",
                                                                                        "phy",
                                                                                        "mac",
                                                                                        "rlc",
                                                                                        "pdcp",
                                                                                        "rrc",
                                                                                        "mme",
                                                                                        "gw",
                                                                                        "user",
                                                                                        "rb",
                                                                                        "timer",
                                                                                        "iface",
                                                                                        "msgq"};

typedef enum{
    LTE_FDD_ENB_PCAP_DIRECTION_UL = 0,
    LTE_FDD_ENB_PCAP_DIRECTION_DL,
    LTE_FDD_ENB_PCAP_DIRECTION_N_ITEMS,
}LTE_FDD_ENB_PCAP_DIRECTION_ENUM;
static const char LTE_fdd_enb_pcap_direction_text[LTE_FDD_ENB_PCAP_DIRECTION_N_ITEMS][20] = {"UL",
                                                                                             "DL"};

typedef enum{
    LTE_FDD_ENB_VAR_TYPE_DOUBLE = 0,
    LTE_FDD_ENB_VAR_TYPE_INT64,
    LTE_FDD_ENB_VAR_TYPE_HEX,
    LTE_FDD_ENB_VAR_TYPE_UINT32,
}LTE_FDD_ENB_VAR_TYPE_ENUM;

typedef enum{
    // System parameters managed by LTE_fdd_enb_cnfg_db
    LTE_FDD_ENB_PARAM_BANDWIDTH = 0,
    LTE_FDD_ENB_PARAM_FREQ_BAND,
    LTE_FDD_ENB_PARAM_DL_EARFCN,
    LTE_FDD_ENB_PARAM_UL_EARFCN,
    LTE_FDD_ENB_PARAM_DL_CENTER_FREQ,
    LTE_FDD_ENB_PARAM_UL_CENTER_FREQ,
    LTE_FDD_ENB_PARAM_N_RB_DL,
    LTE_FDD_ENB_PARAM_N_RB_UL,
    LTE_FDD_ENB_PARAM_DL_BW,
    LTE_FDD_ENB_PARAM_N_SC_RB_DL,
    LTE_FDD_ENB_PARAM_N_SC_RB_UL,
    LTE_FDD_ENB_PARAM_N_ANT,
    LTE_FDD_ENB_PARAM_N_ID_CELL,
    LTE_FDD_ENB_PARAM_N_ID_2,
    LTE_FDD_ENB_PARAM_N_ID_1,
    LTE_FDD_ENB_PARAM_MCC,
    LTE_FDD_ENB_PARAM_MNC,
    LTE_FDD_ENB_PARAM_CELL_ID,
    LTE_FDD_ENB_PARAM_TRACKING_AREA_CODE,
    LTE_FDD_ENB_PARAM_Q_RX_LEV_MIN,
    LTE_FDD_ENB_PARAM_P0_NOMINAL_PUSCH,
    LTE_FDD_ENB_PARAM_P0_NOMINAL_PUCCH,
    LTE_FDD_ENB_PARAM_SIB3_PRESENT,
    LTE_FDD_ENB_PARAM_Q_HYST,
    LTE_FDD_ENB_PARAM_SIB4_PRESENT,
    LTE_FDD_ENB_PARAM_SIB5_PRESENT,
    LTE_FDD_ENB_PARAM_SIB6_PRESENT,
    LTE_FDD_ENB_PARAM_SIB7_PRESENT,
    LTE_FDD_ENB_PARAM_SIB8_PRESENT,
    LTE_FDD_ENB_PARAM_SEARCH_WIN_SIZE,
    LTE_FDD_ENB_PARAM_SYSTEM_INFO_VALUE_TAG,
    LTE_FDD_ENB_PARAM_SYSTEM_INFO_WINDOW_LENGTH,
    LTE_FDD_ENB_PARAM_PHICH_RESOURCE,
    LTE_FDD_ENB_PARAM_N_SCHED_INFO,
    LTE_FDD_ENB_PARAM_SYSTEM_INFO_PERIODICITY,
    LTE_FDD_ENB_PARAM_MAC_DIRECT_TO_UE,
    LTE_FDD_ENB_PARAM_PHY_DIRECT_TO_UE,
    LTE_FDD_ENB_PARAM_DEBUG_TYPE,
    LTE_FDD_ENB_PARAM_DEBUG_LEVEL,
    LTE_FDD_ENB_PARAM_ENABLE_PCAP,
    LTE_FDD_ENB_PARAM_IP_ADDR_START,
    LTE_FDD_ENB_PARAM_DNS_ADDR,
    LTE_FDD_ENB_PARAM_USE_CNFG_FILE,
    LTE_FDD_ENB_PARAM_USE_USER_FILE,
    LTE_FDD_ENB_PARAM_TX_GAIN,
    LTE_FDD_ENB_PARAM_RX_GAIN,

    // Radio parameters managed by LTE_fdd_enb_radio
    LTE_FDD_ENB_PARAM_AVAILABLE_RADIOS,
    LTE_FDD_ENB_PARAM_SELECTED_RADIO_NAME,
    LTE_FDD_ENB_PARAM_SELECTED_RADIO_IDX,
    LTE_FDD_ENB_PARAM_CLOCK_SOURCE,

    LTE_FDD_ENB_PARAM_N_ITEMS,
}LTE_FDD_ENB_PARAM_ENUM;
static const char LTE_fdd_enb_param_text[LTE_FDD_ENB_PARAM_N_ITEMS][100] = {"bandwidth",
                                                                            "band",
                                                                            "dl_earfcn",
                                                                            "ul_earfcn",
                                                                            "dl_center_freq",
                                                                            "ul_center_freq",
                                                                            "n_rb_dl",
                                                                            "n_rb_ul",
                                                                            "dl_bw",
                                                                            "n_sc_rb_dl",
                                                                            "n_sc_rb_ul",
                                                                            "n_ant",
                                                                            "n_id_cell",
                                                                            "n_id_2",
                                                                            "n_id_1",
                                                                            "mcc",
                                                                            "mnc",
                                                                            "cell_id",
                                                                            "tracking_area_code",
                                                                            "q_rx_lev_min",
                                                                            "p0_nominal_pusch",
                                                                            "p0_nominal_pucch",
                                                                            "sib3_present",
                                                                            "q_hyst",
                                                                            "sib4_present",
                                                                            "sib5_present",
                                                                            "sib6_present",
                                                                            "sib7_present",
                                                                            "sib8_present",
                                                                            "search_win_size",
                                                                            "system_info_value_tag",
                                                                            "system_info_window_length",
                                                                            "phich_resource",
                                                                            "n_sched_info",
                                                                            "system_info_periodicity",
                                                                            "mac_direct_to_ue",
                                                                            "phy_direct_to_ue",
                                                                            "debug_type",
                                                                            "debug_level",
                                                                            "enable_pcap",
                                                                            "ip_addr_start",
                                                                            "dns_addr",
                                                                            "use_cnfg_file",
                                                                            "use_user_file",
                                                                            "tx_gain",
                                                                            "rx_gain",
                                                                            "available_radios",
                                                                            "selected_radio_name",
                                                                            "selected_radio_idx",
                                                                            "clock_source"};

typedef struct{
    LTE_FDD_ENB_VAR_TYPE_ENUM var_type;
    LTE_FDD_ENB_PARAM_ENUM    param;
    double                    double_l_bound;
    double                    double_u_bound;
    int64                     int64_l_bound;
    int64                     int64_u_bound;
    bool                      special_bounds;
    bool                      dynamic;
    bool                      read_only;
}LTE_FDD_ENB_VAR_STRUCT;

/*******************************************************************************
                              CLASS DECLARATIONS
*******************************************************************************/

class LTE_fdd_enb_interface
{
public:
    // Singleton
    static LTE_fdd_enb_interface* get_instance(void);
    static void cleanup(void);

    // Communication
    void set_ctrl_port(int16 port);
    void start_ports(void);
    void stop_ports(void);
    void send_ctrl_msg(std::string msg);
    void send_ctrl_info_msg(std::string msg, ...);
    void send_ctrl_error_msg(LTE_FDD_ENB_ERROR_ENUM error, std::string msg);
    void send_debug_msg(LTE_FDD_ENB_DEBUG_TYPE_ENUM type, LTE_FDD_ENB_DEBUG_LEVEL_ENUM level, std::string file_name, int32 line, std::string msg, ...);
    void send_debug_msg(LTE_FDD_ENB_DEBUG_TYPE_ENUM type, LTE_FDD_ENB_DEBUG_LEVEL_ENUM level, std::string file_name, int32 line, LIBLTE_BIT_MSG_STRUCT *lte_msg, std::string msg, ...);
    void send_debug_msg(LTE_FDD_ENB_DEBUG_TYPE_ENUM type, LTE_FDD_ENB_DEBUG_LEVEL_ENUM level, std::string file_name, int32 line, LIBLTE_BYTE_MSG_STRUCT *lte_msg, std::string msg, ...);
    void open_lte_pcap_fd(void);
    void open_ip_pcap_fd(void);
    void send_lte_pcap_msg(LTE_FDD_ENB_PCAP_DIRECTION_ENUM dir, uint32 rnti, uint32 current_tti, uint8 *msg, uint32 N_bits);
    void send_ip_pcap_msg(uint8 *msg, uint32 N_bytes);
    static void handle_ctrl_msg(std::string msg);
    static void handle_ctrl_connect(void);
    static void handle_ctrl_disconnect(void);
    static void handle_ctrl_error(LIBTOOLS_SOCKET_WRAP_ERROR_ENUM err);
    static void handle_debug_msg(std::string msg);
    static void handle_debug_connect(void);
    static void handle_debug_disconnect(void);
    static void handle_debug_error(LIBTOOLS_SOCKET_WRAP_ERROR_ENUM err);
    sem_t                 ctrl_sem;
    sem_t                 debug_sem;
    FILE                 *lte_pcap_fd;
    FILE                 *ip_pcap_fd;
    libtools_socket_wrap *ctrl_socket;
    libtools_socket_wrap *debug_socket;
    int16                 ctrl_port;
    int16                 debug_port;
    static bool           ctrl_connected;
    static bool           debug_connected;

    // Handlers
    LTE_FDD_ENB_ERROR_ENUM handle_write(std::string msg);
    void handle_add_user(std::string msg);

    // Get/Set
    bool get_shutdown(void);
    bool app_is_started(void);

private:
    // Singleton
    static LTE_fdd_enb_interface *instance;
    LTE_fdd_enb_interface();
    ~LTE_fdd_enb_interface();

    // Handlers
    void handle_read(std::string msg);
    void handle_start(void);
    void handle_stop(void);
    void handle_help(void);
    void handle_del_user(std::string msg);
    void handle_print_users(void);
    void handle_print_registered_users(void);

    // Variables
    std::map<std::string, LTE_FDD_ENB_VAR_STRUCT>  var_map;
    LTE_fdd_enb_pdcp                              *pdcp;
    LTE_fdd_enb_mme                               *mme;
    LTE_fdd_enb_gw                                *gw;
    sem_t                                          start_sem;
    uint32                                         debug_type_mask;
    uint32                                         debug_level_mask;
    bool                                           shutdown;
    bool                                           started;

    // Helpers
    LTE_FDD_ENB_ERROR_ENUM write_value(LTE_FDD_ENB_VAR_STRUCT *var, double value);
    LTE_FDD_ENB_ERROR_ENUM write_value(LTE_FDD_ENB_VAR_STRUCT *var, int64 value);
    LTE_FDD_ENB_ERROR_ENUM write_value(LTE_FDD_ENB_VAR_STRUCT *var, std::string value);
    LTE_FDD_ENB_ERROR_ENUM write_value(LTE_FDD_ENB_VAR_STRUCT *var, uint32 value);

    // Inter-stack communication
    LTE_fdd_enb_msgq *phy_to_mac_comm;
    LTE_fdd_enb_msgq *mac_to_phy_comm;
    LTE_fdd_enb_msgq *mac_to_rlc_comm;
    LTE_fdd_enb_msgq *mac_to_timer_comm;
    LTE_fdd_enb_msgq *rlc_to_mac_comm;
    LTE_fdd_enb_msgq *rlc_to_pdcp_comm;
    LTE_fdd_enb_msgq *pdcp_to_rlc_comm;
    LTE_fdd_enb_msgq *pdcp_to_rrc_comm;
    LTE_fdd_enb_msgq *rrc_to_pdcp_comm;
    LTE_fdd_enb_msgq *rrc_to_mme_comm;
    LTE_fdd_enb_msgq *mme_to_rrc_comm;
    LTE_fdd_enb_msgq *pdcp_to_gw_comm;
    LTE_fdd_enb_msgq *gw_to_pdcp_comm;
};

#endif /* __LTE_FDD_ENB_INTERFACE_H__ */

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章