v2g_server.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2007-2010 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*******************************************************************
  18. *
  19. * @author Sebastian.Kaebisch.EXT@siemens.com
  20. * @version 0.3
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. ********************************************************************/
  24. #include "v2g_server.h"
  25. #include "v2g_service.h"
  26. #include "v2g_serviceDispatcher.h"
  27. #include "doIP.h"
  28. #define MAX_BYTE_SIZE 128
  29. #define MAX_STRING_SIZE 256
  30. #define MAX_STREAM_SIZE 60
  31. int testV2GService(uint8_t* inStream, size_t inStreamLength, uint8_t* outStream, size_t* outStreamLength)
  32. {
  33. static uint8_t byte_array[MAX_BYTE_SIZE]; /* define MAX_BYTE_SIZE before*/
  34. static uint32_t string_array[MAX_STRING_SIZE]; /* define MAX_STRING_SIZE before*/
  35. size_t exiMsgLength;
  36. struct v2gService service;
  37. /* BINARY memory setup */
  38. bytes_t bytes = { MAX_BYTE_SIZE, byte_array, 0 };
  39. /* STRING memory setup */
  40. string_ucs_t string = { MAX_STRING_SIZE, string_array, 0 };
  41. /**********************************************
  42. * Init V2G server and initialize array types *
  43. * for the EXI decoding as well as the offset *
  44. * for the transportation header *
  45. **********************************************/
  46. init_v2gservice(&service, bytes, string, DOIP_HEADER_LENGTH);
  47. /* check, if the DoIP header is correct and determine payload */
  48. if(read_doIPHeader(inStream,inStreamLength, &exiMsgLength))
  49. {
  50. /* DoIP header not correct */
  51. write_doIPNack(outStream, outStreamLength, service.errorCode);
  52. return -1;
  53. }
  54. /****************************************************************************
  55. * Pass the received EXI message stream (inStream + exiMsgLength) to the *
  56. * v2g message dispatcher. The outStream contains the response message *
  57. * stream. *
  58. ****************************************************************************/
  59. if(messageDispatcher(&service, inStream, exiMsgLength, outStream, MAX_STREAM_SIZE, outStreamLength))
  60. {
  61. /* write DoIP failure */
  62. write_doIPNack(outStream, outStreamLength, service.errorCode);
  63. }
  64. else
  65. {
  66. /* write DoIP header */
  67. write_doIPHeader(outStream, outStreamLength, DOIP_EXI_TYPE);
  68. }
  69. return 0;
  70. }