/****************************************************************************
**
** Copyright (C) 2000-2007 TROLLTECH ASA. All rights reserved.
**
** This file is part of the Opensource Edition of the Qtopia Toolkit.
**
** This software is licensed under the terms of the GNU General Public
** License (GPL) version 2.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "htcphonemultiplexer.h"
#include <qatchat.h>
#include <qgsm0710multiplexer.h>
#include <qserialport.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <termios.h>
QTOPIA_EXPORT_PLUGIN( HTCPhoneMultiplexerPlugin )
#ifndef N_TTY
#define N_TTY 0
#endif
#ifndef N_TIHTC
#define N_TIHTC 17
#endif
/* stolen from HCIUART set/get protocol ioctls */
#define TIHTCSETCHAN _IOW('U', 200, int)
#define TIHTCGETCHAN _IOR('U', 201, int)
HTCPhoneMultiplexerPlugin::HTCPhoneMultiplexerPlugin( QObject* parent )
: QSerialIODeviceMultiplexerPlugin( parent )
{
}
HTCPhoneMultiplexerPlugin::~HTCPhoneMultiplexerPlugin()
{
}
bool HTCPhoneMultiplexerPlugin::detect( QSerialIODevice *device )
{
return true;
}
QSerialIODeviceMultiplexer *HTCPhoneMultiplexerPlugin::create
( QSerialIODevice *device )
{
// The HTC needs a special line discipline set on the device.
int fd, ldisc, channel = 0;
QSerialPort *port = qobject_cast<QSerialPort *>( device );
if (port) {
device->discard();
/* Set TTY to N_TIHTC line discipline */
ldisc = N_TIHTC;
if (::ioctl (port->fd(), TIOCSETD, &ldisc) < 0) {
perror("Can't set line discipline");
}
/* Set DEBUG channel */
channel = 0x12;
if (::ioctl(port->fd(), TIHTCSETCHAN, channel) < 0) {
perror("Can't set channel");
}
channel = 0x16;
if (::ioctl(port->fd(), TIHTCSETCHAN, channel) < 0) {
perror("Can't set channel");
}
}
device->discard();
// Issue an innocuous command to wake up the device.
QSerialIODeviceMultiplexer::chat( device, "ATE0" );
//QSerialIODeviceMultiplexer::chatWithResponse( device, "ATZ" );
return new QNullSerialIODeviceMultiplexer( device );
}