/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release
FILE NAME
main.c
DESCRIPTION
Basic Example Application for the Object Push Profile Client (OPPC) library
*/
#include "oppc.h"
#include <message.h>
#include <vm.h>
#include <stdio.h>
#include <panic.h>
#include <stdlib.h>
#include <connection.h>
#include <source.h>
#include <string.h>
#include <ps.h>
/* Fixed Pin code */
#define DEF_PINCODE {'1','2','3','4'}
/* User PS Key used to hold the servers bluetooth address */
#define PSKEY_SVR_BDA 10
/* Default Server Bluetooth Address. Used if PSKEY_SVR_BDA is empty */
#define ADDR_NAP 0x0002
#define ADDR_UAP 0x5b
#define ADDR_LAP 0x009ffa
/* vCalendar to send during a Push Object operation */
static const uint8 vcal[] =
"BEGIN:VCALENDAR\nVERSION:1.0\nBEGIN:VEVENT\nDTSTART:20040812T120000Z\nDTEND:20040812T130000Z\nLOCATION;ENCODING=QUOTED-PRINTABLE:MR3\nDESCRIPTION;ENCODING=QUOTED-PRINTABLE:=20=0D=0AHello,=0D=0A=0D=0AHow about a meeting over lunch to decide schedulling.\nSUMMARY;ENCODING=QUOTED-PRINTABLE:Planning Lunch=20\nPRIORITY:3\nEND:VEVENT\nEND:VCALENDAR\n";
/* MIME type of a vCalendar */
static const uint8 vcalType[] = "text/x-vcalendar";
/* Name of the vCalendar. Must be UTF-16. */
static const uint8 vcalName[]={0,'t',0,'e',0,'s',0,'t',0,'.',0,'v',0,'c',0,'s',0,0};/*"test.vcs";*/
/* vCard to send during a Push Business Card operation */
static const uint8 vcard[] =
"BEGIN:VCARD\nVERSION:2.1\nN:Bloggs;Fred\nTEL;WORK:848302664532\nEMAIL;INTERNET:fred.bloggs@here.invalid\nADR;WORK;CHARSET=UTF-8:;;ABC;Chamberlain House;Kildare Avenue;Newport Pagnell;Berkshire;MK16 3BJ\nEND:VCARD";
/* Name of the vCard. Must be UTF-16. */
static const uint8 vcardName[]={0,'t',0,'e',0,'s',0,'t',0,'.',0,'v',0,'c',0,'f',0,0};/*"test.vcf";*/
typedef struct
{
TaskData task;
/* Session handle to use with the OPPC Library */
OPPC *session;
/* Maximum packet size */
uint16 pktSize;
/* Count of the number of packets sent.
Used to work out which byte to start the next packet with. */
uint16 pktCnt;
/* Has the vCalendar been pushed */
bool sentVCal;
/* Bluetooth address of the OPP Server */
bdaddr bd_addr;
}taskState;
static taskState profile;
static void profile_handler(Task task, MessageId id, Message message)
{
/* Get task control block */
taskState *state = (taskState*)task;
switch(id)
{
case CL_INIT_CFM:
{
CL_INIT_CFM_T *msg = (CL_INIT_CFM_T*)message;
printf("CL_INIT_CFM :- ");
if (msg->status == success)
{
printf("success\n");
ConnectionSmSetSdpSecurityIn(TRUE);
ConnectionSmSetSdpSecurityOut(TRUE, &state->bd_addr);
/* Initialise the OPPC Library */
OppcInit(task, 1);
}
else
printf("failure : %d\n", msg->status);
break;
}
case CL_SM_PIN_CODE_IND:
{
CL_SM_PIN_CODE_IND_T *msg = (CL_SM_PIN_CODE_IND_T*)message;
uint8 pin_code[4] = {'1','2','3','4'};
printf("CL_SM_PIN_REQUEST_IND\n");
ConnectionSmPinCodeResponse(&msg->bd_addr, 4, &pin_code[0]);
break;
}
/* OPP Client Library Messages */
case OPPC_INIT_CFM:
{
OPPC_INIT_CFM_T *msg = (OPPC_INIT_CFM_T*)message;
printf("OPPC_INIT_CFM :- ");
if (msg->status == oppc_success)
{
printf("success\n");
/* Store the handle for this session so we can refer to it later */
state->session=msg->oppc;
/* Start an FTPC connection. Set the max.packet size to 255 bytes */
OppcConnect(state->session, &state->bd_addr, 0xFF);
}
else
printf("failure : %d\n", msg->status);
break;
}
case OPPC_CONNECT_CFM:
{
OPPC_CONNECT_CFM_T *msg = (OPPC_CONNECT_CFM_T*)message;
printf("OPPC_CONNECT_CFM :- ");
if (msg->status == oppc_success)
{
printf("success : 0x%x\n",msg->packetSize);
state->pktSize = msg->packetSize;
if ((sizeof(vcal)-1) <= state->pktSize)
{
/* Push the only packet of the vCalendar.
If the vCard is stored in a source OppcPushObjectSource should be used. */
OppcPushObject(state->session,
sizeof(vcalName), &vcalName[0],
sizeof(vcalType), &vcalType[0],
sizeof(vcal)-1, &vcal[0],
sizeof(vcal)-1, TRUE);
state->pktCnt=0;
}
else
{
/* Push the first packet of the vCalendar.
If the vCard is stored in a source OppcPushObjectSource should be used. */
OppcPushObject(state->session,
sizeof(vcalName), &vcalName[0],
sizeof(vcalType), &vcalType[0],
state->pktSize, &vcal[0],
sizeof(vcal)-1, FALSE);
state->pktCnt=1;
}
state->sentVCal = FALSE;
}
else
printf("failure : %d\n", msg->status);
break;
}
case OPPC_DISCONNECT_IND:
{
OPPC_DISCONNECT_IND_T *msg = (OPPC_DISCONNECT_IND_T*)message;
printf("OPPC_DISCONNECT_IND :- ");
if (msg->status == oppc_success)
{
printf("success\n");
}
else
printf("failure : %d\n", msg->status);
break;
}
case OPPC_PUSH_COMPLETE_IND:
{
OPPC_PUSH_COMPLETE_IND_T *msg = (OPPC_PUSH_COMPLETE_IND_T*)message;
printf("OPPC_PUSH_COMPLETE_IND :- ");
if (msg->status == oppc_success)
{
printf("success\n");
}
else
printf("failure : %d\n", msg->status);
if (!state->sentVCal)
{
state->sentVCal = TRUE;
/* Start to send VCard */
if ((sizeof(vcard)-1) <= state->pktSize)
{
/* Push the only packet of the vCard.
If the vCard is stored in a source OppcPushBusinessCardSource should be used. */
OppcPushBusinessCard(state->session,
sizeof(vcardName), &vcardName[0],
sizeof(vcard)-1, &vcard[0],
sizeof(vcard)-1, TRUE);
state->pktCnt=0;
}
else
{
/* Push the first packet of the vCard.
If the vCard is stored in a source OppcPushBusinessCardSource should be used. */
OppcPushBusinessCard(state->session,
sizeof(vcardName), &vcardName[0],
state->pktSize-1, &vcard[0],
sizeof(vcard)-1, FALSE);
state->pktCnt=1;
}
}
else
/* Start to pull the default business card from the OPP Server */
OppcPullBusinessCard(state->session);
break;
}
case OPPC_PUSH_MORE_DATA_IND:
{
uint16 start = state->pktSize * state->pktCnt;
printf("OPPC_PUSH_MORE_DATA_IND\n");
if (!state->sentVCal)
{ /* Send vCal packet */
uint16 len = (sizeof(vcal)-1) - start;
if (len <= state->pktSize)
/* Push the final packet of the vCalendar.
If the vCard is stored in a source OppcPushNextPacketSource should be used. */
OppcPushNextPacket(state->session, len, &vcal[start], TRUE);
else
/* Push the next packet of the vCalendar.
If the vCard is stored in a source OppcPushNextPacketSource should be used. */
OppcPushNextPacket(state->session, state->pktSize, &vcal[start], FALSE);
}
else
{ /* Send vCard packet */
uint16 len = (sizeof(vcard)-1) - start;
if (len <= state->pktSize)
/* Push the final packet of the vCard.
If the vCard is stored in a source OppcPushNextPacketSource should be used. */
OppcPushNextPacket(state->session, len, &vcard[start], TRUE);
else
/* Push the next packet of the vCard.
If the vCard is stored in a source OppcPushNextPacketSource should be used. */
OppcPushNextPacket(state->session, state->pktSize, &vcard[start], FALSE);
}
state->pktCnt++;
break;
}
case OPPC_PULL_BC_START_IND:
{
OPPC_PULL_BC_START_IND_T *msg = (OPPC_PULL_BC_START_IND_T*