ieee80211p-softmodem.c 4.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/******************************************************************************
 *
 * Copyright(c) EURECOM / Thales Communications & Security
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 * The full GNU General Public License is included in this distribution in the
 * file called LICENSE.
 *
 * Contact Information:
 * Thales Communications & Security <philippe.agostini@thalesgroup.com>
 *
 *****************************************************************************/

/******************************************************************************
 *
 * Includes
 *
 *****************************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "ieee80211p-netlinkapi.h"
#include "phy/DOT11/defs.h"
#include "PHY/TOOLS/defs.h"
#include <stdint.h>
#include <string.h>
#include <pthread.h>

42
#include <rtai_lxrt.h>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <rtai_sem.h>
#include <rtai_msg.h>


/******************************************************************************
 *
 * Definitions
 *
 *****************************************************************************/

enum nl80211_band {
  NL80211_BAND_2GHZ,
  NL80211_BAND_5GHZ,
  NL80211_BAND_5_9GHZ,
  NL80211_BAND_0_8GHZ,
};

enum ieee80211_band {
  IEEE80211_BAND_2GHZ = NL80211_BAND_2GHZ,
  IEEE80211_BAND_5GHZ = NL80211_BAND_5GHZ,
  IEEE80211_BAND_5_9GHZ = NL80211_BAND_5_9GHZ,
  IEEE80211_BAND_0_8GHZ = NL80211_BAND_0_8GHZ,
};

struct ieee80211p_rx_status {
68 69 70
  short data_len; //frame data length in bytes
  char  rssi;     //received power in dBm
  char  rate;     //reveived data rate in units of 100 kbps
71
  enum ieee80211_band band;
72
  char  flags;    //RX flags
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
}; /* struct ieee80211p_rx_status */

extern uint32_t *txdata[2],*rxdata[2];
//CHANNEL_STATUS_t dot11_state = IDLE;
extern int oai_exit;

extern unsigned int *DAQ_MBOX;

extern int Ndbps[8];

extern int32_t rxDATA_F_comp_aggreg2[48*1024];
extern int32_t rxDATA_F_comp_aggreg3[48*1024];

extern uint32_t rxgain[4];
extern uint32_t rxg_max[4], rxg_med[4], rxg_byp[4];

#define FRAME_LENGTH_SAMPLES 76800
#define RX_THRES 60

#define SLOT_DURATION_5MHz 105
#define RX_THRES_dB 40

int tx_sdu_active = 0;
int tx_sdu_length = 0;
char rxsdu[2000];

99 100
void *tx_thread(void *arg)
{
101 102 103 104 105 106 107

  int fd=*((int*)arg);
  RT_TASK *task;
  int ret;
  int i;
  char dummy_data[10];

108

109
  if (fd > 0) {
110 111

    ret = netlink_send(fd,NLCMD_INIT,10,&dummy_data[0]);
112 113 114 115 116

    printf("tx_thread starting, fd %d\n",fd);

    task = rt_task_init_schmod(nam2num("TASK1"), 0, 0, 0, SCHED_FIFO, 0xF);
    mlockall(MCL_CURRENT | MCL_FUTURE);
117 118
    //  rt_make_hard_real_time();

119
    while (!oai_exit) {
120

121
      if (tx_sdu_active == 1)
122 123
        printf("tx_thread: waiting (MBOX %d)\n",((unsigned int*)DAQ_MBOX)[0]);

124
      while(((volatile int)tx_sdu_active) != 0) {
125
        rt_sleep(nano2count(66666));
126
      }
127

128 129 130 131 132 133 134
      printf("tx_thread: calling netlink\n");
      ret = netlink_recv(fd,rxsdu);
      tx_sdu_active = 1;
      tx_sdu_length = ret;

      /*
      if (ret > 0) {
135 136 137 138 139 140 141 142

      printf("received TX SDU: ");
      for (i=0;i<ret;i++) {
      printf("%02hhx ",rxsdu[i]);
      }

      printf("\n");

143 144
      }
      */
145

146
    }
147
  } else {
148 149 150 151
    printf("tx_thread: no netlink\n");
  }

  printf("tx_thread exiting\n");
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  return(0);
}


/******************************************************************************
 *
 * Main
 *
 *****************************************************************************/

/*
int dot11_netlink_init() {

  int fd;
  int ret;
  int i;
  char txdata[10];
170

171
  fd = netlink_init();
172

173 174 175
  if (fd < 0) {
    return -1;
  }
176 177

  ret = netlink_send(fd,NLCMD_INIT,10,&txdata[0]);
178 179 180 181 182 183 184 185



  return(fd);
}

*/