/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013 University of California, Los Angeles
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
 *         Ilya Moiseenko <iliamo@ucla.edu>
 *         Zhenkai Zhu <zhenkai@cs.ucla.edu>
 */

#include "adhoc.hpp"
#include "core/chronoshare-config.hpp"

#if (__APPLE__ && HAVE_COREWLAN)

#include "logging.hpp"
#include <sstream>

using namespace std;

INIT_LOGGER ("Adhoc.OSX");

#import <CoreWLAN/CoreWLAN.h>
#import <CoreWLAN/CoreWLANConstants.h>
#import <CoreWLAN/CWInterface.h>
#import <CoreWLAN/CoreWLANTypes.h>

const NSUInteger g_channel = 11;
static NSString * g_priorNetwork = 0;

bool
Adhoc::CreateAdhoc ()
{
  NSString *networkName = [[NSString alloc] initWithCString:"NDNdirect" encoding:NSASCIIStringEncoding];
  NSString *passphrase = [[NSString alloc] initWithCString:"NDNhello" encoding:NSASCIIStringEncoding];
  NSString *securityMode = [[NSString alloc] initWithCString:"Open" encoding:NSASCIIStringEncoding];

  NSArray *airportInterfaces = [[CWInterface interfaceNames] allObjects];

  //Choose the desired interface . the first one will be enought for this example
  NSString *interfaceName =[airportInterfaces objectAtIndex:0];

  CWInterface *airport = [CWInterface interfaceWithName:interfaceName];

  g_priorNetwork = airport.ssid;
  _LOG_DEBUG ("Prior network: " << [g_priorNetwork cStringUsingEncoding:NSASCIIStringEncoding]);

  _LOG_DEBUG ("Starting adhoc connection");

  NSError *error = nil;
  NSData* data = [networkName dataUsingEncoding:NSUTF8StringEncoding];
  BOOL created = [airport startIBSSModeWithSSID:data security:kCWIBSSModeSecurityNone channel:g_channel password:passphrase error:&error];

  if (!created)
    {
      return false;
    }

  _LOG_DEBUG ("Creating face for the adhoc connection");

  // should do a better job later, when Ndnx::Control will be implemented

  ostringstream cmd;
  cmd << NDNX_PATH << "/bin/ndndc add / udp 169.254.255.255";
  int ret = system (cmd.str ().c_str ());
  if (ret == 0)
    {
      return true;
    }
  else
    {
      DestroyAdhoc ();
      return false;
    }
}

void
Adhoc::DestroyAdhoc ()
{
  NSArray *airportInterfaces = [[CWInterface interfaceNames] allObjects];

  //Choose the desired interface . the first one will be enought for this example
  NSString *interfaceName = [airportInterfaces objectAtIndex:0];

  CWInterface *airport = [CWInterface interfaceWithName:interfaceName];

  [airport disassociate];

  NSError *err;

  if (g_priorNetwork != 0)
    {
      NSSet *scanResults = [airport scanForNetworksWithName:g_priorNetwork error:&err];

      if([scanResults count] > 0)
        {
          CWNetwork *previousNetwork = [[scanResults allObjects] objectAtIndex:0];

          [airport associateToNetwork:previousNetwork password:nil error:&err];

          g_priorNetwork = 0;
          return;
        }

      g_priorNetwork = 0;
    }

  [airport setPower:NO error:&err];
  [airport setPower:YES error:&err];

  // ok. this trick works.  if just disassociate, then it will stay OFF
  // setting power OFF/ON trick the system to reconnect to default WiFi
}

#endif // ADHOC_SUPPORTED
