mirror of
https://github.com/Martin-P/OpenV2G.git
synced 2024-11-08 12:45:42 +00:00
v2gv2gtp for 0.7
git-svn-id: https://svn.code.sf.net/p/openv2g/code/trunk@75 d9f2db14-54d0-4bde-b00c-16405c910529
This commit is contained in:
parent
57ff27930c
commit
97e9cc9f3b
2 changed files with 151 additions and 0 deletions
97
src/transport/v2gtp.c
Normal file
97
src/transport/v2gtp.c
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2012 Siemens AG
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
*
|
||||||
|
* @author Sebastian.Kaebisch.EXT@siemens.com
|
||||||
|
* @version 0.7
|
||||||
|
* @contact Joerg.Heuer@siemens.com
|
||||||
|
*
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file implements the v2gtp header writer and reader.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "v2gtp.h"
|
||||||
|
|
||||||
|
|
||||||
|
int write_v2gtpHeader(uint8_t* outStream, uint32_t* outStreamLength, uint16_t payloadType)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* write v2gtp version number 1=byte */
|
||||||
|
outStream[0]=V2GTP_VERSION;
|
||||||
|
|
||||||
|
/* write inverse v2gtp version */
|
||||||
|
outStream[1]=V2GTP_VERSION_INV;
|
||||||
|
|
||||||
|
|
||||||
|
/* write payload type */
|
||||||
|
outStream[3] = (uint8_t)(payloadType & 0xFF);
|
||||||
|
outStream[2] = (uint8_t)(payloadType >> 8 & 0xFF);
|
||||||
|
|
||||||
|
/* write payload length */
|
||||||
|
outStream[7] = (uint8_t)(*outStreamLength & 0xFF);
|
||||||
|
outStream[6] = (uint8_t)(*outStreamLength>>8 & 0xFF);
|
||||||
|
outStream[5] = (uint8_t)(*outStreamLength>>16 & 0xFF);
|
||||||
|
outStream[4] = (uint8_t)(*outStreamLength>>24 & 0xFF);
|
||||||
|
|
||||||
|
/* here, the outStream length have to be resized by the v2gtp offset*/
|
||||||
|
*outStreamLength += V2GTP_HEADER_LENGTH;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_v2gtpHeader(uint8_t* inStream, uint32_t inStreamLength, uint32_t* payloadLength)
|
||||||
|
{
|
||||||
|
uint16_t payloadType=0;
|
||||||
|
|
||||||
|
|
||||||
|
/* check, if we support this v2gtp version */
|
||||||
|
if(inStream[0]!=V2GTP_VERSION && inStream[1]!=V2GTP_VERSION_INV)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
/* check, if we support this payload type*/
|
||||||
|
payloadType = inStream[2];
|
||||||
|
payloadType = (payloadType << 8 | inStream[3]);
|
||||||
|
|
||||||
|
if(payloadType != V2GTP_EXI_TYPE)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
/* determine payload length*/
|
||||||
|
*payloadLength = inStream[4];
|
||||||
|
*payloadLength = (*payloadLength << 8 | inStream[5]);
|
||||||
|
*payloadLength = (*payloadLength << 16 | inStream[6]);
|
||||||
|
*payloadLength = (*payloadLength << 24 | inStream[7]);
|
||||||
|
|
||||||
|
if((*payloadLength+V2GTP_HEADER_LENGTH)!=inStreamLength)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
54
src/transport/v2gtp.h
Normal file
54
src/transport/v2gtp.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2011 Siemens AG
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
*
|
||||||
|
* @author Sebastian.Kaebisch.EXT@siemens.com
|
||||||
|
* @version 0.7
|
||||||
|
* @contact Joerg.Heuer@siemens.com
|
||||||
|
*
|
||||||
|
********************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef V2GTP_H_
|
||||||
|
#define V2GTP_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* generic V2GTP header length */
|
||||||
|
#define V2GTP_HEADER_LENGTH 8
|
||||||
|
|
||||||
|
/* define V2GTP Version */
|
||||||
|
#define V2GTP_VERSION 0x01
|
||||||
|
#define V2GTP_VERSION_INV 0xFE
|
||||||
|
|
||||||
|
/* define V2GTP payload types*/
|
||||||
|
#define V2GTP_EXI_TYPE 0x8001
|
||||||
|
|
||||||
|
int write_v2gtpHeader(uint8_t* outStream, uint32_t* outStreamLength, uint16_t payloadType);
|
||||||
|
|
||||||
|
int read_v2gtpHeader(uint8_t* inStream, uint32_t inStreamLength, uint32_t* payloadLength);
|
||||||
|
|
||||||
|
#endif /* V2GTP_H_ */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in a new issue