main_example.c 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749
  1. /*
  2. * Copyright (C) 2007-2018 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 Daniel.Peintner.EXT@siemens.com
  20. * @author Sebastian.Kaebisch@siemens.com
  21. * @version 0.9.4
  22. * @contact Richard.Kuntschke@siemens.com
  23. *
  24. *
  25. ********************************************************************/
  26. #include <stdio.h>
  27. #include <stdarg.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "../codec/EXITypes.h"
  31. #include "../appHandshake/appHandEXIDatatypes.h"
  32. #include "../appHandshake/appHandEXIDatatypesEncoder.h"
  33. #include "../appHandshake/appHandEXIDatatypesDecoder.h"
  34. /* Activate support for DIN */
  35. #include "../din/dinEXIDatatypes.h"
  36. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  37. #include "../din/dinEXIDatatypesEncoder.h"
  38. #include "../din/dinEXIDatatypesDecoder.h"
  39. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  40. /* Activate support for XMLDSIG */
  41. #include "../xmldsig/xmldsigEXIDatatypes.h"
  42. #if DEPLOY_XMLDSIG_CODEC == SUPPORT_YES
  43. #include "../xmldsig/xmldsigEXIDatatypesEncoder.h"
  44. #include "../xmldsig/xmldsigEXIDatatypesDecoder.h"
  45. #endif /* DEPLOY_XMLDSIG_CODEC == SUPPORT_YES */
  46. /* Activate support for ISO1 */
  47. #include "../iso1/iso1EXIDatatypes.h"
  48. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  49. #include "../iso1/iso1EXIDatatypesEncoder.h"
  50. #include "../iso1/iso1EXIDatatypesDecoder.h"
  51. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  52. /* Activate support for ISO2 */
  53. #include "../iso2/iso2EXIDatatypes.h"
  54. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  55. #include "../iso2/iso2EXIDatatypesEncoder.h"
  56. #include "../iso2/iso2EXIDatatypesDecoder.h"
  57. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  58. #include "../transport/v2gtp.h"
  59. //#include "../../SeccComm.h"
  60. #define BUFFER_SIZE 256
  61. uint8_t buffer1[BUFFER_SIZE];
  62. uint8_t buffer2[BUFFER_SIZE];
  63. #define ERROR_UNEXPECTED_REQUEST_MESSAGE -601
  64. #define ERROR_UNEXPECTED_SESSION_SETUP_RESP_MESSAGE -602
  65. #define ERROR_UNEXPECTED_SERVICE_DISCOVERY_RESP_MESSAGE -602
  66. #define ERROR_UNEXPECTED_SERVICE_DETAILS_RESP_MESSAGE -603
  67. #define ERROR_UNEXPECTED_PAYMENT_SERVICE_SELECTION_RESP_MESSAGE -604
  68. #define ERROR_UNEXPECTED_PAYMENT_DETAILS_RESP_MESSAGE -605
  69. #define ERROR_UNEXPECTED_AUTHORIZATION_RESP_MESSAGE -606
  70. #define ERROR_UNEXPECTED_CHARGE_PARAMETER_DISCOVERY_RESP_MESSAGE -607
  71. #define ERROR_UNEXPECTED_POWER_DELIVERY_RESP_MESSAGE -608
  72. #define ERROR_UNEXPECTED_CHARGING_STATUS_RESP_MESSAGE -609
  73. #define ERROR_UNEXPECTED_METERING_RECEIPT_RESP_MESSAGE -610
  74. #define ERROR_UNEXPECTED_SESSION_STOP_RESP_MESSAGE -611
  75. #define ERROR_UNEXPECTED_CABLE_CHECK_RESP_MESSAGE -612
  76. #define ERROR_UNEXPECTED_PRE_CHARGE_RESP_MESSAGE -612
  77. #define ERROR_UNEXPECTED_CURRENT_DEMAND_RESP_MESSAGE -613
  78. #define ERROR_UNEXPECTED_WELDING_DETECTION_RESP_MESSAGE -614
  79. /*===========================================================================
  80. FUNCTION: PRINT_XML_DOC_DIN_ServiceDiscoveryReq
  81. DESCRIPTION:
  82. PRE-CONDITION:
  83. INPUT:
  84. OUTPUT:
  85. GLOBAL VARIABLES:
  86. =============================================================================*/
  87. void PRINT_XML_DOC_DIN_ServiceDiscoveryReq(struct dinEXIDocument *exi_doc_DIN)
  88. {
  89. int i = 0;
  90. printf("\n\n⬇⨀⨀⨀⨀⨀ [START] Parsing ServiceDiscoveryReq ⨀⨀⨀⨀⨀⬇\n");
  91. //Service Scope
  92. int leng = 0;
  93. leng = exi_doc_DIN->V2G_Message.Body.ServiceDiscoveryReq.ServiceScope.charactersLen;
  94. printf("\tServieScope (%d Bytes)= ", leng);
  95. for (i = 0; i <leng ; i++)
  96. {
  97. printf("%02X", exi_doc_DIN->V2G_Message.Body.ServiceDiscoveryReq.ServiceScope.characters[i]);
  98. }
  99. //Service Category
  100. printf("\n\tServiceCategory = %d (DEC)",
  101. exi_doc_DIN->V2G_Message.Body.ServiceDiscoveryReq.ServiceCategory);
  102. printf("\n\t([1]EVCharging, [2]Internet, [3]ContractCertificate, [4]OtherCustom)\n");
  103. printf("⬆⨂⨂⨂⨂⨂ [END] Parsing ServiceDiscoveryReq ⨂⨂⨂⨂⨂⬆\n\n");
  104. }
  105. static int writeStringToEXIString(char* string, exi_string_character_t* exiString) {
  106. int pos = 0;
  107. while(string[pos]!='\0')
  108. {
  109. exiString[pos] = string[pos];
  110. pos++;
  111. }
  112. return pos;
  113. }
  114. static void printASCIIString(exi_string_character_t* string, uint16_t len) {
  115. unsigned int i;
  116. for(i=0; i<len; i++) {
  117. printf("%c",(char)string[i]);
  118. }
  119. printf("\n");
  120. }
  121. static void printBinaryArray(uint8_t* byte, uint16_t len) {
  122. unsigned int i;
  123. for(i=0; i<len; i++) {
  124. printf("%d ",byte[i]);
  125. }
  126. printf("\n");
  127. }
  128. static void copyBytes(uint8_t* from, uint16_t len, uint8_t* to) {
  129. int i;
  130. for(i=0; i<len; i++) {
  131. to[i] = from[i];
  132. }
  133. }
  134. /** Example implementation of the app handshake protocol for the EVSE side */
  135. static int appHandshakeHandler(bitstream_t* iStream, bitstream_t* oStream) {
  136. struct appHandEXIDocument appHandResp;
  137. int i;
  138. struct appHandEXIDocument exiDoc;
  139. int errn = 0;
  140. uint32_t payloadLengthDec;
  141. #if 1
  142. printf("\n\n ----------- Content of iStream [START]------------\n\n");
  143. printf("\t size (DEC): %d\n", (int)iStream->size);
  144. printf("\t pos (DEC): %ld\n", *iStream->pos);
  145. printf("\t data (HEX): ");
  146. for (i=0; i<68; i++) //0x44 = 68, i.e. the length of payload
  147. {
  148. printf("%02X", iStream->data[i+8]); //V2GTP Payload without 8-Byte Header
  149. }
  150. printf("\n\n ----------- Content of iStream [END] ------------\n\n");
  151. #endif
  152. if ( (errn = read_v2gtpHeader(iStream->data, &payloadLengthDec)) == 0) {
  153. *iStream->pos = V2GTP_HEADER_LENGTH;
  154. printf("\t pos: %ld\n", *iStream->pos); //added by Joseph
  155. if( (errn = decode_appHandExiDocument(iStream, &exiDoc)) ) {
  156. /* an error occured */
  157. return errn;
  158. }
  159. }
  160. printf("EVSE side: List of application handshake protocols of the EV \n");
  161. for(i=0;i<exiDoc.supportedAppProtocolReq.AppProtocol.arrayLen;i++)
  162. {
  163. printf("\tProtocol entry #=%d\n",(i+1));
  164. printf("\t\tProtocolNamespace=");
  165. printASCIIString(exiDoc.supportedAppProtocolReq.AppProtocol.array[i].ProtocolNamespace.characters, exiDoc.supportedAppProtocolReq.AppProtocol.array[i].ProtocolNamespace.charactersLen);
  166. printf("\t\tVersion=%d.%d\n", exiDoc.supportedAppProtocolReq.AppProtocol.array[i].VersionNumberMajor, exiDoc.supportedAppProtocolReq.AppProtocol.array[i].VersionNumberMinor);
  167. printf("\t\tSchemaID=%d\n", exiDoc.supportedAppProtocolReq.AppProtocol.array[i].SchemaID);
  168. printf("\t\tPriority=%d\n", exiDoc.supportedAppProtocolReq.AppProtocol.array[i].Priority);
  169. }
  170. /* prepare response handshake response:
  171. * it is assumed, we support the 15118 1.0 version :-) */
  172. init_appHandEXIDocument(&appHandResp);
  173. appHandResp.supportedAppProtocolRes_isUsed = 1u;
  174. appHandResp.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  175. appHandResp.supportedAppProtocolRes.SchemaID = exiDoc.supportedAppProtocolReq.AppProtocol.array[0].SchemaID; /* signal the protocol by the provided schema id*/
  176. appHandResp.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  177. *oStream->pos = V2GTP_HEADER_LENGTH;
  178. if( (errn = encode_appHandExiDocument(oStream, &appHandResp)) == 0)
  179. {
  180. errn = write_v2gtpHeader(oStream->data, (*oStream->pos)-V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  181. }
  182. return errn;
  183. }
  184. static int appHandshake()
  185. {
  186. bitstream_t stream1;
  187. bitstream_t stream2;
  188. uint32_t payloadLengthDec;
  189. size_t pos1 = V2GTP_HEADER_LENGTH; /* v2gtp header */
  190. size_t pos2 = 0;
  191. struct appHandEXIDocument handshake;
  192. struct appHandEXIDocument handshakeResp;
  193. int errn = 0;
  194. char* ns0 = "urn:iso:15118:2:2010:MsgDef";
  195. char* ns1 = "urn:din:70121:2012:MsgDef";
  196. stream1.size = BUFFER_SIZE;
  197. stream1.data = buffer1;
  198. stream1.pos = &pos1;
  199. stream2.size = BUFFER_SIZE;
  200. stream2.data = buffer2;
  201. stream2.pos = &pos2;
  202. init_appHandEXIDocument(&handshake);
  203. printf("EV side: setup data for the supported application handshake request message\n");
  204. /* set up ISO/IEC 15118 Version 1.0 information */
  205. handshake.supportedAppProtocolReq_isUsed = 1u;
  206. handshake.supportedAppProtocolReq.AppProtocol.arrayLen = 2; /* we have only two protocols implemented */
  207. handshake.supportedAppProtocolReq.AppProtocol.array[0].ProtocolNamespace.charactersLen =
  208. writeStringToEXIString(ns0, handshake.supportedAppProtocolReq.AppProtocol.array[0].ProtocolNamespace.characters);
  209. handshake.supportedAppProtocolReq.AppProtocol.array[0].SchemaID = 1;
  210. handshake.supportedAppProtocolReq.AppProtocol.array[0].VersionNumberMajor = 1;
  211. handshake.supportedAppProtocolReq.AppProtocol.array[0].VersionNumberMinor = 0;
  212. handshake.supportedAppProtocolReq.AppProtocol.array[0].Priority = 1;
  213. handshake.supportedAppProtocolReq.AppProtocol.array[1].ProtocolNamespace.charactersLen =
  214. writeStringToEXIString(ns1, handshake.supportedAppProtocolReq.AppProtocol.array[1].ProtocolNamespace.characters);
  215. handshake.supportedAppProtocolReq.AppProtocol.array[1].SchemaID = 2;
  216. handshake.supportedAppProtocolReq.AppProtocol.array[1].VersionNumberMajor = 1;
  217. handshake.supportedAppProtocolReq.AppProtocol.array[1].VersionNumberMinor = 0;
  218. handshake.supportedAppProtocolReq.AppProtocol.array[1].Priority = 2;
  219. /* send app handshake request */
  220. if( (errn = encode_appHandExiDocument(&stream1, &handshake)) == 0) {
  221. if ( write_v2gtpHeader(stream1.data, pos1-V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE) == 0 ) {
  222. printf("EV side: send message to the EVSE\n");
  223. }
  224. }
  225. if (errn == 0) {
  226. /* read app handshake request & generate response */
  227. errn = appHandshakeHandler(&stream1, &stream2);
  228. }
  229. if (errn == 0) {
  230. /* check response */
  231. if ( (errn = read_v2gtpHeader(stream2.data, &payloadLengthDec)) == 0) {
  232. pos2 = V2GTP_HEADER_LENGTH;
  233. if(decode_appHandExiDocument(&stream2, &handshakeResp) == 0) {
  234. printf("EV side: Response of the EVSE \n");
  235. if(handshakeResp.supportedAppProtocolRes.ResponseCode == appHandresponseCodeType_OK_SuccessfulNegotiation) {
  236. printf("\t\tResponseCode=OK_SuccessfulNegotiation\n");
  237. printf("\t\tSchemaID=%d\n",handshakeResp.supportedAppProtocolRes.SchemaID);
  238. }
  239. }
  240. }
  241. }
  242. if (errn != 0) {
  243. printf("appHandshake error %d \n", errn);
  244. }
  245. return errn;
  246. }
  247. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  248. static void printEVSEStatus2(struct iso2EVSEStatusType* status)
  249. {
  250. printf("\tEVSEStatus:\n");
  251. printf("\t\tEVSENotification=%d\n", status->EVSENotification);
  252. printf("\t\tNotificationMaxDelay=%d\n", status->NotificationMaxDelay);
  253. }
  254. /* serializes EXI stream and adds V2G TP header */
  255. static int serialize2EXI2Stream(struct iso2EXIDocument* exiIn, bitstream_t* stream) {
  256. int errn;
  257. *stream->pos = V2GTP_HEADER_LENGTH; /* v2gtp header */
  258. if( (errn = encode_iso2ExiDocument(stream, exiIn)) == 0) {
  259. errn = write_v2gtpHeader(stream->data, (*stream->pos)-V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  260. }
  261. return errn;
  262. }
  263. /* deserializes V2G TP header and decodes right away EXI stream */
  264. static int deserialize2Stream2EXI(bitstream_t* streamIn, struct iso2EXIDocument* exi) {
  265. int errn;
  266. uint32_t payloadLength;
  267. *streamIn->pos = 0;
  268. if ( (errn = read_v2gtpHeader(streamIn->data, &payloadLength)) == 0) {
  269. *streamIn->pos += V2GTP_HEADER_LENGTH;
  270. errn = decode_iso2ExiDocument(streamIn, exi);
  271. }
  272. return errn;
  273. }
  274. static int sessionSetup2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  275. printf("EVSE side: sessionSetup called\n" );
  276. printf("\tReceived data:\n");
  277. printf("\tHeader SessionID=");
  278. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  279. printf("\t\t EVCCID=%d\n", exiIn->V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0]);
  280. exiOut->V2G_Message_isUsed = 1u;
  281. /* generate an unique sessionID */
  282. init_iso2MessageHeaderType(&exiOut->V2G_Message.Header);
  283. exiOut->V2G_Message.Header.SessionID.bytes[0] = 1;
  284. exiOut->V2G_Message.Header.SessionID.bytes[1] = 2;
  285. exiOut->V2G_Message.Header.SessionID.bytes[2] = 3;
  286. exiOut->V2G_Message.Header.SessionID.bytes[3] = 4;
  287. exiOut->V2G_Message.Header.SessionID.bytes[4] = 5;
  288. exiOut->V2G_Message.Header.SessionID.bytes[5] = 6;
  289. exiOut->V2G_Message.Header.SessionID.bytes[6] = 7;
  290. exiOut->V2G_Message.Header.SessionID.bytes[7] = 8;
  291. exiOut->V2G_Message.Header.SessionID.bytesLen = 8;
  292. /* Prepare data for EV */
  293. init_iso2BodyType(&exiOut->V2G_Message.Body);
  294. exiOut->V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  295. init_iso2SessionSetupResType(&exiOut->V2G_Message.Body.SessionSetupRes);
  296. exiOut->V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK;
  297. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.characters[0] = 0;
  298. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.characters[1] = 20;
  299. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 2;
  300. exiOut->V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  301. exiOut->V2G_Message.Body.SessionSetupRes.EVSETimeStamp = 123456789;
  302. return 0;
  303. }
  304. static int serviceDiscovery2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  305. int i;
  306. printf("EVSE side: serviceDiscovery called\n" );
  307. printf("\tReceived data:\n");
  308. printf("\tHeader SessionID=");
  309. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  310. if(exiIn->V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs_isUsed) {
  311. for(i=0;i<exiIn->V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs.ServiceID.arrayLen; i++) {
  312. printf("\t\tSupportedServiceID=%d\n", exiIn->V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs.ServiceID.array[i]);
  313. }
  314. }
  315. /* Prepare data for EV */
  316. exiOut->V2G_Message_isUsed = 1u;
  317. init_iso2BodyType(&exiOut->V2G_Message.Body);
  318. exiOut->V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  319. init_iso2ServiceDiscoveryResType(&exiOut->V2G_Message.Body.ServiceDiscoveryRes);
  320. exiOut->V2G_Message.Body.ServiceDiscoveryRes.VASList_isUsed = 0u; /* we do not provide VAS */
  321. exiOut->V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso2responseCodeType_OK;
  322. exiOut->V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso2paymentOptionType_ExternalPayment; /* EVSE handles the payment */
  323. exiOut->V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[1] = iso2paymentOptionType_Contract;
  324. exiOut->V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 2;
  325. exiOut->V2G_Message.Body.ServiceDiscoveryRes.EnergyTransferServiceList.Service.arrayLen = 1;
  326. exiOut->V2G_Message.Body.ServiceDiscoveryRes.EnergyTransferServiceList.Service.array[0].ServiceID = 1; /* ID of the charge service */
  327. exiOut->V2G_Message.Body.ServiceDiscoveryRes.EnergyTransferServiceList.Service.array[0].FreeService = 1;
  328. exiOut->V2G_Message.Body.ServiceDiscoveryRes.VASList_isUsed = 0u; /* no value added service requested */
  329. return 0;
  330. }
  331. static int serviceDetail2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  332. printf("EVSE side: serviceDetail called\n" );
  333. printf("\tReceived data:\n");
  334. printf("\tHeader SessionID=");
  335. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  336. printf("\t\t ServiceDetailID=%d\n",exiIn->V2G_Message.Body.ServiceDetailReq.ServiceID);
  337. /* Prepare data for EV */
  338. exiOut->V2G_Message_isUsed = 1u;
  339. init_iso2BodyType(&exiOut->V2G_Message.Body);
  340. exiOut->V2G_Message.Body.ServiceDetailRes_isUsed= 1u;
  341. init_iso2ServiceDetailResType(&exiOut->V2G_Message.Body.ServiceDetailRes);
  342. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceID = 1234;
  343. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList_isUsed = 1u;
  344. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen = 2;
  345. /* Parameter Set 1*/
  346. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].ParameterSetID = 1;
  347. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.arrayLen = 2;
  348. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.charactersLen = 8;
  349. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[0] = 'P';
  350. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[1] = 'r';
  351. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[2] = 'o';
  352. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[3] = 't';
  353. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[4]= 'o';
  354. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[5] = 'c';
  355. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[6] = 'o';
  356. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[7] = 'l';
  357. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].intValue = 15119;
  358. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].intValue_isUsed = 1u;
  359. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.charactersLen = 4;
  360. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[0] = 'N';
  361. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[1] = 'a';
  362. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[2] = 'm';
  363. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[3] = 'e';
  364. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue_isUsed = 1u;
  365. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.charactersLen = 3;
  366. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[0] = 'V';
  367. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[1] = '2';
  368. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[2] = 'G';
  369. /* Parameter Set 2 */
  370. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].ParameterSetID = 2;
  371. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.arrayLen = 1;
  372. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.charactersLen = 7;
  373. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[0] = 'C';
  374. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[1] = 'h';
  375. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[2] = 'a';
  376. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[3] = 'n';
  377. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[4] = 'n';
  378. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[5] = 'e';
  379. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[6] = 'l';
  380. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue_isUsed = 1u;
  381. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Value = 1234;
  382. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Exponent = 1;
  383. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Value = 2;
  384. exiOut->V2G_Message.Body.ServiceDetailRes.ResponseCode = iso2responseCodeType_OK;
  385. return 0;
  386. }
  387. static int paymentServiceSelection2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  388. int i;
  389. printf("EVSE side: paymentServiceSelection called\n" );
  390. printf("\tReceived data:\n");
  391. printf("\tHeader SessionID=");
  392. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  393. if(exiIn->V2G_Message.Body.PaymentServiceSelectionReq.SelectedPaymentOption == iso2paymentOptionType_ExternalPayment) {
  394. printf("\t\t SelectedPaymentOption=ExternalPayment\n");
  395. }
  396. if(exiIn->V2G_Message.Body.PaymentServiceSelectionReq.SelectedVASList_isUsed) {
  397. for(i=0; i<exiIn->V2G_Message.Body.PaymentServiceSelectionReq.SelectedVASList.SelectedService.arrayLen;i++)
  398. {
  399. printf("\t\t ServiceID=%d\n", exiIn->V2G_Message.Body.PaymentServiceSelectionReq.SelectedVASList.SelectedService.array[i].ServiceID);
  400. printf("\t\t ParameterSetID=%d\n", exiIn->V2G_Message.Body.PaymentServiceSelectionReq.SelectedVASList.SelectedService.array[i].ParameterSetID);
  401. }
  402. }
  403. /* Prepare data for EV */
  404. exiOut->V2G_Message_isUsed = 1u;
  405. init_iso2BodyType(&exiOut->V2G_Message.Body);
  406. exiOut->V2G_Message.Body.PaymentServiceSelectionRes_isUsed= 1u;
  407. init_iso2PaymentServiceSelectionResType(&exiOut->V2G_Message.Body.PaymentServiceSelectionRes);
  408. exiOut->V2G_Message.Body.ServiceDetailRes.ResponseCode = iso2responseCodeType_OK;
  409. return 0;
  410. }
  411. static int paymentDetails2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  412. printf("EVSE side: paymentDetails called\n" );
  413. printf("\tReceived data:\n");
  414. printf("\t\t eMAID=%d\n", exiIn->V2G_Message.Body.PaymentDetailsReq.eMAID.characters[0]);
  415. printf("\t\t ID=%c%c\n", exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id.characters[0], exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id.characters[1]);
  416. printf("\t\t Certificate=%c%c\n", exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Certificate.bytes[0], exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Certificate.bytes[1]);
  417. printf("\t\t SubCertificate 1=%c%c\n", exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[0].bytes[0], exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[0].bytes[1]);
  418. printf("\t\t SubCertificate 2=%c%c\n", exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytes[0], exiIn->V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytes[1]);
  419. /* Prepare data for EV */
  420. exiOut->V2G_Message_isUsed = 1u;
  421. init_iso2BodyType(&exiOut->V2G_Message.Body);
  422. exiOut->V2G_Message.Body.PaymentDetailsRes_isUsed = 1u;
  423. init_iso2PaymentDetailsResType(&exiOut->V2G_Message.Body.PaymentDetailsRes);
  424. exiOut->V2G_Message.Body.PaymentDetailsRes.ResponseCode = iso2responseCodeType_OK;
  425. exiOut->V2G_Message.Body.PaymentDetailsRes.GenChallenge.bytesLen = 1;
  426. exiOut->V2G_Message.Body.PaymentDetailsRes.GenChallenge.bytes[0] = 1;
  427. exiOut->V2G_Message.Body.PaymentDetailsRes.EVSETimeStamp = 123456;
  428. return 0;
  429. }
  430. static int authorization2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  431. printf("EVSE: Authorization called\n" );
  432. printf("\tReceived data:\n");
  433. if(exiIn->V2G_Message.Body.AuthorizationReq.GenChallenge_isUsed) {
  434. printf("\t\t\t GenChallenge=%d\n", exiIn->V2G_Message.Body.AuthorizationReq.GenChallenge.bytes[0]);
  435. }
  436. if(exiIn->V2G_Message.Body.AuthorizationReq.Id_isUsed ) {
  437. printf("\t\t\t ID=%c%c%c\n", exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[0], exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[1], exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[2]);
  438. }
  439. /* Prepare data for EV */
  440. exiOut->V2G_Message_isUsed = 1u;
  441. init_iso2BodyType(&exiOut->V2G_Message.Body);
  442. exiOut->V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  443. init_iso2AuthorizationResType(&exiOut->V2G_Message.Body.AuthorizationRes);
  444. exiOut->V2G_Message.Body.AuthorizationRes.ResponseCode = iso2responseCodeType_OK;
  445. exiOut->V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso2EVSEProcessingType_Finished;
  446. return 0;
  447. }
  448. static int chargeParameterDiscovery2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  449. printf("EVSE side: chargeParameterDiscovery called\n" );
  450. printf("\tReceived data:\n");
  451. if(exiIn->V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter_isUsed) {
  452. printf("\t\t DepartureTime=%d\n", exiIn->V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.DepartureTime);
  453. printf("\t\t EVMaximumChargeCurrent=%d\n", exiIn->V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumChargeCurrent.Value);
  454. }
  455. /* Prepare data for EV */
  456. exiOut->V2G_Message_isUsed = 1u;
  457. init_iso2BodyType(&exiOut->V2G_Message.Body);
  458. exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  459. init_iso2ChargeParameterDiscoveryResType(&exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes);
  460. exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes.ResponseCode = iso2responseCodeType_OK_CertificateExpiresSoon;
  461. exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes.EVSEProcessing = iso2EVSEProcessingType_Ongoing;
  462. exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes.EVSEEnergyTransferParameter_isUsed = 1u;
  463. /*exiOut->V2G_Message.Body.ChargeParameterDiscoveryRes.EVSEEnergyTransferParameter = 0;*/
  464. return 0;
  465. }
  466. static int powerDelivery2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  467. printf("EVSE side: powerDelivery called\n" );
  468. printf("\tReceived data:\n");
  469. printf("\t\t ChargeProgress=%d\n", exiIn->V2G_Message.Body.PowerDeliveryReq.ChargeProgress);
  470. printf("\t\t SAScheduleTupleID=%d\n", exiIn->V2G_Message.Body.PowerDeliveryReq.SAScheduleTupleID);
  471. /* Prepare data for EV */
  472. exiOut->V2G_Message_isUsed = 1u;
  473. init_iso2BodyType(&exiOut->V2G_Message.Body);
  474. exiOut->V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  475. init_iso2PowerDeliveryResType(&exiOut->V2G_Message.Body.PowerDeliveryRes);
  476. exiOut->V2G_Message.Body.PowerDeliveryRes.ResponseCode = iso2responseCodeType_OK;
  477. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus_isUsed = 1;
  478. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus.EVSENotification = iso2EVSENotificationType_StopCharging;
  479. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus.NotificationMaxDelay=12;
  480. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEProcessing = iso2EVSEProcessingType_Ongoing_WaitingForCustomerInteraction;
  481. return 0;
  482. }
  483. static int chargingStatus2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  484. printf("EVSE side: chargingStatus called\n" );
  485. /* Prepare data for EV */
  486. exiOut->V2G_Message_isUsed = 1u;
  487. init_iso2BodyType(&exiOut->V2G_Message.Body);
  488. exiOut->V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  489. init_iso2ChargingStatusResType(&exiOut->V2G_Message.Body.ChargingStatusRes);
  490. exiOut->V2G_Message.Body.ChargingStatusRes.ResponseCode = iso2responseCodeType_OK;
  491. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEID.characters[0]= 'A';
  492. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEID.charactersLen =1;
  493. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEStatus.EVSENotification = iso2EVSENotificationType_ReNegotiation;
  494. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEStatus.NotificationMaxDelay=123;
  495. exiOut->V2G_Message.Body.ChargingStatusRes.ReceiptRequired = 1;
  496. exiOut->V2G_Message.Body.ChargingStatusRes.ReceiptRequired_isUsed = 1;
  497. return 0;
  498. }
  499. static int meteringReceipt2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  500. printf("EVSE side: meteringReceipt called\n" );
  501. printf("\tReceived data:\n");
  502. printf("\t\t ID=%c%c%c\n", exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[0], exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[1], exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[2]);
  503. printf("\t\t SAScheduleTupleID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.SAScheduleTupleID);
  504. printf("\t\t SessionID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.SessionID.bytes[1]);
  505. printf("\t\t MeterInfo.MeterStatus=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterStatus);
  506. printf("\t\t MeterInfo.MeterID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.characters[0]);
  507. /* Prepare data for EV */
  508. exiOut->V2G_Message_isUsed = 1u;
  509. init_iso2BodyType(&exiOut->V2G_Message.Body);
  510. exiOut->V2G_Message.Body.MeteringReceiptRes_isUsed = 1u;
  511. init_iso2MeteringReceiptResType(&exiOut->V2G_Message.Body.MeteringReceiptRes);
  512. exiOut->V2G_Message.Body.MeteringReceiptRes.ResponseCode = iso2responseCodeType_FAILED;
  513. return 0;
  514. }
  515. static int sessionStop2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  516. printf("EVSE side: sessionStop called\n" );
  517. printf("\tReceived data:\n");
  518. printf("\tHeader SessionID=");
  519. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  520. printf("\t\t ChargingSession=%d\n", exiIn->V2G_Message.Body.SessionStopReq.ChargingSession);
  521. /* Prepare data for EV */
  522. exiOut->V2G_Message_isUsed = 1u;
  523. init_iso2BodyType(&exiOut->V2G_Message.Body);
  524. exiOut->V2G_Message.Body.SessionStopRes_isUsed = 1u;
  525. init_iso2SessionStopResType(&exiOut->V2G_Message.Body.SessionStopRes);
  526. exiOut->V2G_Message.Body.SessionStopRes.ResponseCode = iso2responseCodeType_OK;
  527. return 0;
  528. }
  529. static int cableCheck2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  530. printf("EVSE side: cableCheck called\n" );
  531. /* Prepare data for EV */
  532. exiOut->V2G_Message_isUsed = 1u;
  533. init_iso2BodyType(&exiOut->V2G_Message.Body);
  534. exiOut->V2G_Message.Body.CableCheckRes_isUsed = 1u;
  535. init_iso2CableCheckResType(&exiOut->V2G_Message.Body.CableCheckRes);
  536. exiOut->V2G_Message.Body.CableCheckRes.ResponseCode = iso2responseCodeType_OK;
  537. exiOut->V2G_Message.Body.CableCheckRes.EVSEStatus.NotificationMaxDelay = 1234;
  538. exiOut->V2G_Message.Body.CableCheckRes.EVSEStatus.EVSENotification= iso2EVSENotificationType_ReNegotiation;
  539. exiOut->V2G_Message.Body.CableCheckRes.EVSEProcessing = iso2EVSEProcessingType_Finished;
  540. return 0;
  541. }
  542. static int preCharge2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  543. printf("EVSE side: preCharge called\n" );
  544. printf("\tReceived data:\n");
  545. printf("\t\t EVTargetCurrent=%d (%d)\n", exiIn->V2G_Message.Body.PreChargeReq.EVTargetCurrent.Value, exiIn->V2G_Message.Body.PreChargeReq.EVTargetCurrent.Exponent);
  546. printf("\t\t EVTargetVoltage=%d (%d)\n", exiIn->V2G_Message.Body.PreChargeReq.EVTargetVoltage.Value, exiIn->V2G_Message.Body.PreChargeReq.EVTargetVoltage.Exponent);
  547. /* Prepare data for EV */
  548. exiOut->V2G_Message_isUsed = 1u;
  549. init_iso2BodyType(&exiOut->V2G_Message.Body);
  550. exiOut->V2G_Message.Body.PreChargeRes_isUsed = 1u;
  551. init_iso2PreChargeResType(&exiOut->V2G_Message.Body.PreChargeRes);
  552. exiOut->V2G_Message.Body.PreChargeRes.ResponseCode = iso2responseCodeType_OK;
  553. exiOut->V2G_Message.Body.PreChargeRes.EVSEStatus.EVSENotification = iso2EVSENotificationType_StopCharging;
  554. exiOut->V2G_Message.Body.PreChargeRes.EVSEStatus.NotificationMaxDelay= 1234;
  555. exiOut->V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Exponent = 3;
  556. exiOut->V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value= 456;
  557. return 0;
  558. }
  559. static int create_response_message2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  560. int errn = ERROR_UNEXPECTED_REQUEST_MESSAGE;
  561. /* create response message as EXI document */
  562. if(exiIn->V2G_Message_isUsed) {
  563. init_iso2EXIDocument(exiOut);
  564. if (exiIn->V2G_Message.Body.SessionSetupReq_isUsed) {
  565. errn = sessionSetup2(exiIn, exiOut);
  566. } else if (exiIn->V2G_Message.Body.ServiceDiscoveryReq_isUsed) {
  567. errn = serviceDiscovery2(exiIn, exiOut);
  568. } else if (exiIn->V2G_Message.Body.ServiceDetailReq_isUsed) {
  569. errn = serviceDetail2(exiIn, exiOut);
  570. } else if (exiIn->V2G_Message.Body.PaymentServiceSelectionReq_isUsed) {
  571. errn = paymentServiceSelection2(exiIn, exiOut);
  572. } else if (exiIn->V2G_Message.Body.PaymentDetailsReq_isUsed) {
  573. errn = paymentDetails2(exiIn, exiOut);
  574. } else if (exiIn->V2G_Message.Body.AuthorizationReq_isUsed) {
  575. errn = authorization2(exiIn, exiOut);
  576. } else if (exiIn->V2G_Message.Body.ChargeParameterDiscoveryReq_isUsed) {
  577. errn = chargeParameterDiscovery2(exiIn, exiOut);
  578. } else if (exiIn->V2G_Message.Body.PowerDeliveryReq_isUsed) {
  579. errn = powerDelivery2(exiIn, exiOut);
  580. } else if (exiIn->V2G_Message.Body.ChargingStatusReq_isUsed) {
  581. errn = chargingStatus2(exiIn, exiOut);
  582. } else if (exiIn->V2G_Message.Body.MeteringReceiptReq_isUsed) {
  583. errn = meteringReceipt2(exiIn, exiOut);
  584. } else if (exiIn->V2G_Message.Body.SessionStopReq_isUsed) {
  585. errn = sessionStop2(exiIn, exiOut);
  586. } else if (exiIn->V2G_Message.Body.CableCheckReq_isUsed) {
  587. errn = cableCheck2(exiIn, exiOut);
  588. } else if (exiIn->V2G_Message.Body.PreChargeReq_isUsed) {
  589. errn = preCharge2(exiIn, exiOut);
  590. }
  591. }
  592. return errn;
  593. }
  594. /* Adapt this to your system setup! */
  595. /* In this situation EV and EVSE is the same party */
  596. static int request_response2(struct iso2EXIDocument* exiIn, struct iso2EXIDocument* exiOut) {
  597. int errn;
  598. bitstream_t stream1;
  599. bitstream_t stream2;
  600. size_t pos1;
  601. size_t pos2;
  602. stream1.size = BUFFER_SIZE;
  603. stream1.data = buffer1;
  604. stream1.pos = &pos1;
  605. stream2.size = BUFFER_SIZE;
  606. stream2.data = buffer2;
  607. stream2.pos = &pos2;
  608. /* EV side */
  609. errn = serialize2EXI2Stream(exiIn, &stream1);
  610. /* --> Start of EVSE side */
  611. /* deserialize request message */
  612. if (errn == 0) {
  613. errn = deserialize2Stream2EXI(&stream1, exiOut);
  614. }
  615. /* create response message */
  616. if (errn == 0) {
  617. errn = create_response_message2(exiOut, exiIn);
  618. }
  619. /* serialize response message */
  620. if (errn == 0) {
  621. errn = serialize2EXI2Stream(exiIn, &stream2);
  622. }
  623. /* <-- End of EVSE side */
  624. /* EV side */
  625. /* deserialize response message */
  626. if (errn == 0) {
  627. errn = deserialize2Stream2EXI(&stream2, exiOut);
  628. }
  629. return errn;
  630. }
  631. static int charging2()
  632. {
  633. int errn = 0;
  634. int i, j;
  635. struct iso2EXIDocument exiIn;
  636. struct iso2EXIDocument exiOut;
  637. struct iso2ServiceDetailResType serviceDetailRes;
  638. struct iso2PaymentServiceSelectionResType paymentServiceSelectionRes;
  639. struct iso2PaymentDetailsResType paymentDetailsRes;
  640. /* setup header information */
  641. init_iso2EXIDocument(&exiIn);
  642. exiIn.V2G_Message_isUsed = 1u;
  643. init_iso2MessageHeaderType(&exiIn.V2G_Message.Header);
  644. exiIn.V2G_Message.Header.SessionID.bytes[0] = 0; /* sessionID is always '0' at the beginning (the response contains the valid sessionID)*/
  645. exiIn.V2G_Message.Header.SessionID.bytes[1] = 0;
  646. exiIn.V2G_Message.Header.SessionID.bytes[2] = 0;
  647. exiIn.V2G_Message.Header.SessionID.bytes[3] = 0;
  648. exiIn.V2G_Message.Header.SessionID.bytes[4] = 0;
  649. exiIn.V2G_Message.Header.SessionID.bytes[5] = 0;
  650. exiIn.V2G_Message.Header.SessionID.bytes[6] = 0;
  651. exiIn.V2G_Message.Header.SessionID.bytes[7] = 0;
  652. exiIn.V2G_Message.Header.SessionID.bytesLen = 8;
  653. exiIn.V2G_Message.Header.Signature_isUsed = 0u;
  654. /************************
  655. * sessionSetup *
  656. ************************/
  657. init_iso2BodyType(&exiIn.V2G_Message.Body);
  658. exiIn.V2G_Message.Body.SessionSetupReq_isUsed = 1u;
  659. init_iso2SessionSetupReqType(&exiIn.V2G_Message.Body.SessionSetupReq);
  660. exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytesLen = 1;
  661. exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0] = 10;
  662. printf("EV side: call EVSE sessionSetup");
  663. errn = request_response2(&exiIn, &exiOut);
  664. if(errn == 0) {
  665. /* check, if this is the right response message */
  666. if(exiOut.V2G_Message.Body.SessionSetupRes_isUsed) {
  667. /* show results of EVSEs answer message */
  668. printf("EV side: received response message from EVSE\n");
  669. printf("\tHeader SessionID=");
  670. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  671. printf("\tResponseCode=%d\n", exiOut.V2G_Message.Body.SessionSetupRes.ResponseCode);
  672. printf("\tEVSEID=%d\n", exiOut.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]);
  673. printf("\tEVSETimeStamp=%li\n", (long int)exiOut.V2G_Message.Body.SessionSetupRes.EVSETimeStamp);
  674. } else {
  675. errn = ERROR_UNEXPECTED_SESSION_SETUP_RESP_MESSAGE;
  676. return errn;
  677. }
  678. } else {
  679. return errn;
  680. }
  681. /*******************************************
  682. * serviceDiscovery *
  683. *******************************************/
  684. init_iso2BodyType(&exiIn.V2G_Message.Body);
  685. exiIn.V2G_Message.Body.ServiceDiscoveryReq_isUsed = 1u;
  686. init_iso2ServiceDiscoveryReqType(&exiIn.V2G_Message.Body.ServiceDiscoveryReq);
  687. exiIn.V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs_isUsed = 1u;
  688. exiIn.V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs.ServiceID.arrayLen = 1;
  689. exiIn.V2G_Message.Body.ServiceDiscoveryReq.SupportedServiceIDs.ServiceID.array[0] = iso2serviceCategoryType_Internet;
  690. printf("EV side: call EVSE serviceDiscovery");
  691. errn = request_response2(&exiIn, &exiOut);
  692. if(errn == 0) {
  693. /* check, if this is the right response message */
  694. if(exiOut.V2G_Message.Body.ServiceDiscoveryRes_isUsed) {
  695. /* show results of EVSEs answer message */
  696. printf("EV side: received response message from EVSE\n");
  697. printf("\tHeader SessionID=");
  698. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  699. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode);
  700. printf("\t Service ResponseCode=%d\n", exiOut.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode);
  701. /*printf("\t ServiceID=%d\n", exiOut.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID);
  702. printf("\t ServiceName=");
  703. printASCIIString(serviceDiscoveryRes.ChargeService.ServiceName.characters, serviceDiscoveryRes.ChargeService.ServiceName.charactersLen);
  704. if(serviceDiscoveryRes.PaymentOptionList.PaymentOption.array[1] == v2gpaymentOptionType_Contract) {
  705. printf("\t PaymentOption=Contract_paymentOptionType\n");
  706. }
  707. if(serviceDiscoveryRes.ChargeService.FreeService==1) {
  708. printf("\t ChargeService.FreeService=True\n");
  709. }
  710. if(serviceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] == v2gEnergyTransferModeType_DC_combo_core) {
  711. printf("\t EnergyTransferMode=AC_single_DC_core\n");
  712. }
  713. if(serviceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[1] == v2gEnergyTransferModeType_AC_single_phase_core) {
  714. printf("\t EnergyTransferMode=AC_single_phase_core_EnergyTransferModeType\n");
  715. }
  716. printf("\t Value added service list:\n");
  717. for(i=0;i<serviceDiscoveryRes.ServiceList.Service.arrayLen;i++)
  718. {
  719. printf("\n\t\t ServiceID=%d\n", serviceDiscoveryRes.ServiceList.Service.array[i].ServiceID);
  720. printf("\t\t ServiceName=");
  721. printASCIIString(serviceDiscoveryRes.ServiceList.Service.array[i].ServiceName.characters, exiOut.V2G_Message.Body.ServiceDiscoveryRes.ServiceList.Service.array[i].ServiceName.charactersLen );
  722. if(serviceDiscoveryRes.ServiceList.Service.array[i].ServiceCategory == v2gserviceCategoryType_Internet) {
  723. printf("\t\t ServiceCategory=Internet\n");
  724. }
  725. if(serviceDiscoveryRes.ServiceList.Service.array[i].FreeService==1) {
  726. printf("\t\t FreeService=True\n");
  727. }
  728. }*/
  729. } else {
  730. errn = ERROR_UNEXPECTED_SERVICE_DISCOVERY_RESP_MESSAGE;
  731. return errn;
  732. }
  733. } else {
  734. return errn;
  735. }
  736. /*********************************
  737. * ServiceDetails *
  738. *********************************/
  739. init_iso2BodyType(&exiIn.V2G_Message.Body);
  740. exiIn.V2G_Message.Body.ServiceDetailReq_isUsed = 1u;
  741. init_iso2ServiceDetailReqType(&exiIn.V2G_Message.Body.ServiceDetailReq);
  742. exiIn.V2G_Message.Body.ServiceDetailReq.ServiceID = 22; /* Value Added Server ID */
  743. printf("EV side: call EVSE ServiceDetail \n");
  744. errn = request_response2(&exiIn, &exiOut);
  745. if(errn == 0) {
  746. /* check, if this is the right response message */
  747. if(exiOut.V2G_Message.Body.ServiceDetailRes_isUsed) {
  748. serviceDetailRes = exiOut.V2G_Message.Body.ServiceDetailRes;
  749. /* show results of EVSEs answer message */
  750. printf("EV side: received response message from EVSE\n");
  751. printf("\tHeader SessionID=");
  752. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  753. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode);
  754. printf("\t ServiceID=%d\n", exiOut.V2G_Message.Body.ServiceDetailRes.ServiceID);
  755. if(serviceDetailRes.ServiceParameterList_isUsed) {
  756. printf("\t\tLength=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.arrayLen );/*TEST*/
  757. for(i=0; i<serviceDetailRes.ServiceParameterList.ParameterSet.arrayLen; i++)
  758. {
  759. printf("\t\tServiceSetID=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.array[i].ParameterSetID);
  760. printf("\t\tParameters=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.arrayLen);
  761. for(j=0; j<serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.arrayLen; j++)
  762. {
  763. printf("\t\t\t %d: ParameterName=", j+1);
  764. printASCIIString(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].Name.characters, exiOut.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].Name.charactersLen);
  765. /*if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].shortValue_isUsed == 1u) {
  766. printf("\t\t\t %d: StringValue=", j+1);
  767. printASCIIString(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].stringValue.characters, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].stringValue.charactersLen);
  768. } else if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].intValue_isUsed == 1u) {
  769. printf("\t\t\t %d: IntValue=%d\n", j+1, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].intValue);
  770. } else if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue_isUsed == 1u) {
  771. printf("\t\t\t %d: PhysicalValue=%d (%d)\n", j+1, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue.Value, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue.Multiplier);
  772. }*/
  773. }
  774. }
  775. }
  776. } else {
  777. errn = ERROR_UNEXPECTED_SERVICE_DETAILS_RESP_MESSAGE;
  778. return errn;
  779. }
  780. } else {
  781. return errn;
  782. }
  783. /*******************************************
  784. * ServicePaymentSelection *
  785. *******************************************/
  786. init_iso2BodyType(&exiIn.V2G_Message.Body);
  787. exiIn.V2G_Message.Body.PaymentServiceSelectionReq_isUsed = 1u;
  788. init_iso2PaymentServiceSelectionReqType(&exiIn.V2G_Message.Body.PaymentServiceSelectionReq);
  789. exiIn.V2G_Message.Body.PaymentServiceSelectionReq.SelectedPaymentOption = iso2paymentOptionType_ExternalPayment;
  790. exiIn.V2G_Message.Body.PaymentServiceSelectionReq.SelectedVASList_isUsed = 0u;
  791. exiIn.V2G_Message.Body.PaymentServiceSelectionReq.SelectedEnergyTransferService.ServiceID = 1;
  792. exiIn.V2G_Message.Body.PaymentServiceSelectionReq.SelectedEnergyTransferService.ParameterSetID = 4;
  793. printf("EV side: call EVSE ServicePaymentSelection \n");
  794. errn = request_response2(&exiIn, &exiOut);
  795. if(errn == 0) {
  796. /* check, if this is the right response message */
  797. if(exiOut.V2G_Message.Body.PaymentServiceSelectionRes_isUsed) {
  798. paymentServiceSelectionRes = exiOut.V2G_Message.Body.PaymentServiceSelectionRes;
  799. /* show results of EVSEs answer message */
  800. printf("EV side: received response message from EVSE\n");
  801. if(exiOut.V2G_Message.Body.PaymentServiceSelectionRes.EVSEStatus_isUsed) {
  802. printf("\tHeader SessionID=");
  803. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  804. }
  805. printf("\t ResponseCode=%d\n", paymentServiceSelectionRes.ResponseCode);
  806. } else {
  807. errn = ERROR_UNEXPECTED_PAYMENT_SERVICE_SELECTION_RESP_MESSAGE;
  808. return errn;
  809. }
  810. } else {
  811. return errn;
  812. }
  813. /**********************************
  814. * PaymentDetails *
  815. **********************************/
  816. init_iso2BodyType(&exiIn.V2G_Message.Body);
  817. exiIn.V2G_Message.Body.PaymentDetailsReq_isUsed = 1u;
  818. init_iso2PaymentDetailsReqType(&exiIn.V2G_Message.Body.PaymentDetailsReq);
  819. exiIn.V2G_Message.Body.PaymentDetailsReq.eMAID.characters[0] = 1;
  820. exiIn.V2G_Message.Body.PaymentDetailsReq.eMAID.characters[1] = 123;
  821. exiIn.V2G_Message.Body.PaymentDetailsReq.eMAID.charactersLen =2;
  822. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Certificate.bytes[0] = 'C';
  823. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Certificate.bytes[1] = 'e';
  824. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Certificate.bytesLen = 2;
  825. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates_isUsed = 1u;
  826. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[0].bytes[0] = 'S';
  827. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[0].bytes[1] = 'u';
  828. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[0].bytesLen = 2;
  829. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytes[0] = 'S';
  830. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytes[1] = 'u';
  831. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytes[2] = '2';
  832. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.array[1].bytesLen = 3;
  833. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.SubCertificates.Certificate.arrayLen =2;
  834. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id_isUsed = 1u;
  835. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id.charactersLen = 2;
  836. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id.characters[0] = 'I';
  837. exiIn.V2G_Message.Body.PaymentDetailsReq.ContractSignatureCertChain.Id.characters[0] = 'd';
  838. printf("EV side: call EVSE ServiceDetail \n");
  839. errn = request_response2(&exiIn, &exiOut);
  840. if(errn == 0) {
  841. /* check, if this is the right response message */
  842. if(exiOut.V2G_Message.Body.PaymentDetailsRes_isUsed) {
  843. paymentDetailsRes = exiOut.V2G_Message.Body.PaymentDetailsRes;
  844. printf("EV side: received response message from EVSE\n");
  845. /* show results of EVSEs answer message */
  846. printf("\tHeader SessionID=");
  847. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  848. printf("\t ResponseCode=%d\n", paymentDetailsRes.ResponseCode);
  849. printf("\tEVSETimeStamp=%li\n", (long int) paymentDetailsRes.EVSETimeStamp);
  850. printf("\tGenChallenge=%d\n", paymentDetailsRes.GenChallenge.bytes[0]);
  851. } else {
  852. errn = ERROR_UNEXPECTED_PAYMENT_DETAILS_RESP_MESSAGE;
  853. return errn;
  854. }
  855. } else {
  856. return errn;
  857. }
  858. /*******************************************
  859. * Authorization *
  860. *******************************************/
  861. init_iso2BodyType(&exiIn.V2G_Message.Body);
  862. exiIn.V2G_Message.Body.AuthorizationReq_isUsed = 1u;
  863. init_iso2AuthorizationReqType(&exiIn.V2G_Message.Body.AuthorizationReq);
  864. copyBytes(paymentDetailsRes.GenChallenge.bytes, paymentDetailsRes.GenChallenge.bytesLen, exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge.bytes);
  865. exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge.bytesLen = paymentDetailsRes.GenChallenge.bytesLen;
  866. exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge_isUsed = 1u; /* no challenge needed here*/
  867. exiIn.V2G_Message.Body.AuthorizationReq.Id_isUsed = 1u; /* no signature needed here */
  868. exiIn.V2G_Message.Body.AuthorizationReq.Id.charactersLen = 3;
  869. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[0] = 'I';
  870. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[1] = 'd';
  871. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[2] = '2';
  872. printf("EV side: call EVSE Authorization \n");
  873. errn = request_response2(&exiIn, &exiOut);
  874. if(errn == 0) {
  875. /* check, if this is the right response message */
  876. if(exiOut.V2G_Message.Body.AuthorizationRes_isUsed) {
  877. /* show results of EVSEs answer message */
  878. printf("EV side: received response message from EVSE\n");
  879. printf("\tHeader SessionID=");
  880. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  881. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.AuthorizationRes.ResponseCode);
  882. if(exiOut.V2G_Message.Body.AuthorizationRes.EVSEProcessing == iso2EVSEProcessingType_Finished) {
  883. printf("\t EVSEProcessing=Finished\n");
  884. }
  885. } else {
  886. errn = ERROR_UNEXPECTED_AUTHORIZATION_RESP_MESSAGE;
  887. return errn;
  888. }
  889. } else {
  890. return errn;
  891. }
  892. /*******************************************
  893. * chargeParameterDiscovery *
  894. *******************************************/
  895. init_iso2BodyType(&exiIn.V2G_Message.Body);
  896. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq_isUsed = 1u;
  897. init_iso2ChargeParameterDiscoveryReqType(&exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq);
  898. /* we use here AC based charging parameters */
  899. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.MaxSupportingPoints_isUsed = 1u;
  900. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.MaxSupportingPoints = 1234;
  901. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter_isUsed = 1u;
  902. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.DepartureTime = 12345;
  903. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumChargePower.Exponent = 0;
  904. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumChargePower.Value = 100;
  905. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumChargeCurrent.Exponent = 0;
  906. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumChargeCurrent.Value = 400;
  907. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMinimumChargeCurrent.Exponent = 0;
  908. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMinimumChargeCurrent.Value = 200;
  909. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumVoltage.Exponent = 0;
  910. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumVoltage.Value = 400;
  911. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumDischargePower.Exponent = 0;
  912. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumDischargePower.Value = 200;
  913. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumDischargeCurrent.Exponent = 0;
  914. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMaximumDischargeCurrent.Value = 400;
  915. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMinimumDischargeCurrent.Exponent = 0;
  916. exiIn.V2G_Message.Body.ChargeParameterDiscoveryReq.AC_EVBidirectionalParameter.EVMinimumDischargeCurrent.Value = 200;
  917. printf("EV side: call EVSE chargeParameterDiscovery");
  918. errn = request_response2(&exiIn, &exiOut);
  919. if(errn == 0) {
  920. /* check, if this is the right response message */
  921. if(exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed) {
  922. /* show results of EVSEs answer message */
  923. printf("EV side: received response message from EVSE\n");
  924. printf("\tHeader SessionID=");
  925. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  926. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.ResponseCode);
  927. /*printACEVSEStatus(&(exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.AC_EVSEChargeParameter.AC_EVSEStatus));
  928. printf("\t EVSEProcessing=%d\n", exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.EVSEProcessing);
  929. printf("\t EVSEMaxCurrent=%d\n", exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.AC_EVSEChargeParameter.EVSEMaxCurrent.Value);
  930. printf("\t EVSENominalVoltage=%d\n", exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.AC_EVSEChargeParameter.EVSENominalVoltage.Value);*/
  931. } else {
  932. errn = ERROR_UNEXPECTED_CHARGE_PARAMETER_DISCOVERY_RESP_MESSAGE;
  933. return errn;
  934. }
  935. } else {
  936. return errn;
  937. }
  938. /*****************************
  939. * cableCheck *
  940. *****************************/
  941. init_iso2BodyType(&exiIn.V2G_Message.Body);
  942. exiIn.V2G_Message.Body.CableCheckReq_isUsed = 1u;
  943. /*init_v2gCableCheckReqType(&exiIn.V2G_Message.Body.CableCheckReq);*/
  944. printf("EV side: call EVSE cableCheck \n");
  945. errn = request_response2(&exiIn, &exiOut);
  946. if(errn == 0) {
  947. /* check, if this is the right response message */
  948. if(exiOut.V2G_Message.Body.CableCheckRes_isUsed) {
  949. /* show results of EVSEs answer message */
  950. printf("EV side: received response message from EVSE\n");
  951. printf("\tHeader SessionID=");
  952. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  953. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.CableCheckRes.ResponseCode);
  954. if(exiOut.V2G_Message.Body.CableCheckRes.EVSEProcessing==iso2EVSEProcessingType_Finished) {
  955. printf("\tEVSEProcessing=Finished\n");
  956. }
  957. printEVSEStatus2(&(exiOut.V2G_Message.Body.CableCheckRes.EVSEStatus));
  958. } else {
  959. errn = ERROR_UNEXPECTED_CABLE_CHECK_RESP_MESSAGE;
  960. return errn;
  961. }
  962. } else {
  963. return errn;
  964. }
  965. /*****************************
  966. * preCharge *
  967. *****************************/
  968. init_iso2BodyType(&exiIn.V2G_Message.Body);
  969. exiIn.V2G_Message.Body.PreChargeReq_isUsed = 1u;
  970. init_iso2PreChargeReqType(&exiIn.V2G_Message.Body.PreChargeReq);
  971. exiIn.V2G_Message.Body.PreChargeReq.EVTargetCurrent.Exponent = 1;
  972. exiIn.V2G_Message.Body.PreChargeReq.EVTargetCurrent.Value = 234;
  973. exiIn.V2G_Message.Body.PreChargeReq.EVTargetVoltage.Exponent = 1;
  974. exiIn.V2G_Message.Body.PreChargeReq.EVTargetVoltage.Value = 100;
  975. printf("EV side: call EVSE preCharge \n");
  976. errn = request_response2(&exiIn, &exiOut);
  977. if(errn == 0) {
  978. /* check, if this is the right response message */
  979. if(exiOut.V2G_Message.Body.PreChargeRes_isUsed) {
  980. /* show results of EVSEs answer message */
  981. printf("EV side: received response message from EVSE\n");
  982. printf("\tHeader SessionID=");
  983. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  984. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.PreChargeRes.ResponseCode);
  985. printEVSEStatus2(&exiOut.V2G_Message.Body.PreChargeRes.EVSEStatus);
  986. printf("\tEVSEPresentVoltage=%d (%d %d)\n", exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value, exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value, exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Exponent);
  987. } else {
  988. errn = ERROR_UNEXPECTED_PRE_CHARGE_RESP_MESSAGE;
  989. return errn;
  990. }
  991. } else {
  992. return errn;
  993. }
  994. /*********************************
  995. * PowerDelivery *
  996. *********************************/
  997. init_iso2BodyType(&exiIn.V2G_Message.Body);
  998. exiIn.V2G_Message.Body.PowerDeliveryReq_isUsed = 1u;
  999. init_iso2PowerDeliveryReqType(&exiIn.V2G_Message.Body.PowerDeliveryReq);
  1000. exiIn.V2G_Message.Body.PowerDeliveryReq.ChargeProgress = iso2chargeProgressType_Start;
  1001. exiIn.V2G_Message.Body.PowerDeliveryReq.SAScheduleTupleID_isUsed = 1u;
  1002. exiIn.V2G_Message.Body.PowerDeliveryReq.SAScheduleTupleID = exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.SAScheduleList.SAScheduleTuple.array[0].SAScheduleTupleID;
  1003. printf("EV side: call EVSE powerDelivery \n");
  1004. errn = request_response2(&exiIn, &exiOut);
  1005. if(errn == 0) {
  1006. /* check, if this is the right response message */
  1007. if(exiOut.V2G_Message.Body.PowerDeliveryRes_isUsed) {
  1008. /* show results of EVSEs answer message */
  1009. printf("EV side: received response message from EVSE\n");
  1010. printf("\tHeader SessionID=");
  1011. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1012. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.PowerDeliveryRes.ResponseCode);
  1013. /*printACEVSEStatus(&(exiOut.V2G_Message.Body.PowerDeliveryRes.AC_EVSEStatus));*/
  1014. } else {
  1015. errn = ERROR_UNEXPECTED_POWER_DELIVERY_RESP_MESSAGE;
  1016. return errn;
  1017. }
  1018. } else {
  1019. return errn;
  1020. }
  1021. /*********************************
  1022. * Setup data for chargingStatus *
  1023. *********************************/
  1024. init_iso2BodyType(&exiIn.V2G_Message.Body);
  1025. exiIn.V2G_Message.Body.ChargingStatusReq_isUsed = 1u;
  1026. init_iso2ChargingStatusReqType(&exiIn.V2G_Message.Body.ChargingStatusReq);
  1027. exiIn.V2G_Message.Body.ChargingStatusReq.EVTargetEnergyRequest.Exponent = 2;
  1028. exiIn.V2G_Message.Body.ChargingStatusReq.EVTargetEnergyRequest.Value = 100;
  1029. printf("EV side: call EVSE chargingStatus \n");
  1030. errn = request_response2(&exiIn, &exiOut);
  1031. if(errn == 0) {
  1032. /* check, if this is the right response message */
  1033. if(exiOut.V2G_Message.Body.ChargingStatusRes_isUsed) {
  1034. /* show results of EVSEs answer message */
  1035. printf("EV side: received response message from EVSE\n");
  1036. printf("\tHeader SessionID=");
  1037. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1038. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.ResponseCode);
  1039. /*printACEVSEStatus(&(exiOut.V2G_Message.Body.ChargingStatusRes.AC_EVSEStatus));
  1040. printf("\tReceiptRequired=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.ReceiptRequired);
  1041. printf("\tEVSEID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.EVSEID.characters[0]);
  1042. printf("\tSAScheduleTupleID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.SAScheduleTupleID);
  1043. printf("\tEVSEMaxCurrent=%d (%d %d)\n", exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Value, exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Unit, exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Multiplier);
  1044. printf("\tisused.MeterInfo=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo_isUsed);
  1045. printf("\t\tMeterInfo.MeterID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterID.characters[0]);
  1046. printf("\t\tMeterInfo.MeterReading.Value=%li\n", (long int)exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterReading);
  1047. printf("\t\tMeterInfo.MeterStatus=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterStatus);
  1048. printf("\t\tMeterInfo.TMeter=%li\n", (long int)exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.TMeter);
  1049. printf("\t\tMeterInfo.SigMeterReading.data=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.SigMeterReading.bytes[0]);*/
  1050. } else {
  1051. errn = ERROR_UNEXPECTED_CHARGING_STATUS_RESP_MESSAGE;
  1052. return errn;
  1053. }
  1054. } else {
  1055. return errn;
  1056. }
  1057. /***********************************
  1058. * MeteringReceipt *
  1059. ***********************************/
  1060. init_iso2BodyType(&exiIn.V2G_Message.Body);
  1061. exiIn.V2G_Message.Body.MeteringReceiptReq_isUsed = 1u;
  1062. init_iso2MeteringReceiptReqType(&exiIn.V2G_Message.Body.MeteringReceiptReq);
  1063. exiIn.V2G_Message.Body.MeteringReceiptReq.Id.characters[0]='I';
  1064. exiIn.V2G_Message.Body.MeteringReceiptReq.Id.characters[1]='d';
  1065. exiIn.V2G_Message.Body.MeteringReceiptReq.Id.characters[2]='3';
  1066. exiIn.V2G_Message.Body.MeteringReceiptReq.Id.charactersLen =3;
  1067. exiIn.V2G_Message.Body.MeteringReceiptReq.SessionID.bytes[0] = 22;
  1068. exiIn.V2G_Message.Body.MeteringReceiptReq.SessionID.bytesLen = 1;
  1069. init_iso2MeterInfoType(&exiIn.V2G_Message.Body.MeteringReceiptReq.MeterInfo);
  1070. exiIn.V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.characters[0] = 'M';
  1071. exiIn.V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.characters[1] = 'i';
  1072. exiIn.V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.characters[2] = 'd';
  1073. exiIn.V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.charactersLen = 3;
  1074. printf("EV side: call EVSE meteringReceipt \n");
  1075. errn = request_response2(&exiIn, &exiOut);
  1076. if(errn == 0) {
  1077. /* check, if this is the right response message */
  1078. if(exiOut.V2G_Message.Body.MeteringReceiptRes_isUsed) {
  1079. /* show results of EVSEs answer message */
  1080. printf("EV side: received response message from EVSE\n");
  1081. printf("\tHeader SessionID=");
  1082. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1083. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.MeteringReceiptRes.ResponseCode);
  1084. } else {
  1085. errn = ERROR_UNEXPECTED_METERING_RECEIPT_RESP_MESSAGE;
  1086. return errn;
  1087. }
  1088. } else {
  1089. return errn;
  1090. }
  1091. /***********************************
  1092. * SessionStop *
  1093. ***********************************/
  1094. init_iso2BodyType(&exiIn.V2G_Message.Body);
  1095. exiIn.V2G_Message.Body.SessionStopReq_isUsed = 1u;
  1096. init_iso2SessionStopReqType(&exiIn.V2G_Message.Body.SessionStopReq);
  1097. exiIn.V2G_Message.Body.SessionStopReq.ChargingSession = iso2chargingSessionType_Pause;
  1098. printf("EV side: call EVSE stopSession \n");
  1099. errn = request_response2(&exiIn, &exiOut);
  1100. if(errn == 0) {
  1101. /* check, if this is the right response message */
  1102. if(exiOut.V2G_Message.Body.SessionStopRes_isUsed) {
  1103. /* show results of EVSEs answer message */
  1104. printf("EV side: received response message from EVSE\n");
  1105. printf("\tHeader SessionID=");
  1106. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1107. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.SessionStopRes.ResponseCode);
  1108. } else {
  1109. errn = ERROR_UNEXPECTED_SESSION_STOP_RESP_MESSAGE;
  1110. return errn;
  1111. }
  1112. } else {
  1113. return errn;
  1114. }
  1115. return errn;
  1116. }
  1117. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  1118. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  1119. static void printEVSEStatus1(struct iso1DC_EVSEStatusType* status)
  1120. {
  1121. printf("\tEVSEStatus:\n");
  1122. printf("\t\tEVSENotification=%d\n", status->EVSENotification);
  1123. printf("\t\tNotificationMaxDelay=%d\n", status->NotificationMaxDelay);
  1124. }
  1125. /* serializes EXI stream and adds V2G TP header */
  1126. static int serialize1EXI2Stream(struct iso1EXIDocument* exiIn, bitstream_t* stream) {
  1127. int errn;
  1128. *stream->pos = V2GTP_HEADER_LENGTH; /* v2gtp header */
  1129. if( (errn = encode_iso1ExiDocument(stream, exiIn)) == 0) {
  1130. errn = write_v2gtpHeader(stream->data, (*stream->pos)-V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  1131. }
  1132. return errn;
  1133. }
  1134. /* deserializes V2G TP header and decodes right away EXI stream */
  1135. static int deserialize1Stream2EXI(bitstream_t* streamIn, struct iso1EXIDocument* exi) {
  1136. int errn;
  1137. uint32_t payloadLength;
  1138. *streamIn->pos = 0;
  1139. if ( (errn = read_v2gtpHeader(streamIn->data, &payloadLength)) == 0) {
  1140. *streamIn->pos += V2GTP_HEADER_LENGTH;
  1141. errn = decode_iso1ExiDocument(streamIn, exi);
  1142. }
  1143. return errn;
  1144. }
  1145. static int sessionSetup1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1146. printf("EVSE side: sessionSetup called\n" );
  1147. printf("\tReceived data:\n");
  1148. printf("\tHeader SessionID=");
  1149. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  1150. printf("\t\t EVCCID=%d\n", exiIn->V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0]);
  1151. exiOut->V2G_Message_isUsed = 1u;
  1152. /* generate an unique sessionID */
  1153. init_iso1MessageHeaderType(&exiOut->V2G_Message.Header);
  1154. exiOut->V2G_Message.Header.SessionID.bytes[0] = 1;
  1155. exiOut->V2G_Message.Header.SessionID.bytes[1] = 2;
  1156. exiOut->V2G_Message.Header.SessionID.bytes[2] = 3;
  1157. exiOut->V2G_Message.Header.SessionID.bytes[3] = 4;
  1158. exiOut->V2G_Message.Header.SessionID.bytes[4] = 5;
  1159. exiOut->V2G_Message.Header.SessionID.bytes[5] = 6;
  1160. exiOut->V2G_Message.Header.SessionID.bytes[6] = 7;
  1161. exiOut->V2G_Message.Header.SessionID.bytes[7] = 8;
  1162. exiOut->V2G_Message.Header.SessionID.bytesLen = 8;
  1163. /* Prepare data for EV */
  1164. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1165. exiOut->V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  1166. init_iso1SessionSetupResType(&exiOut->V2G_Message.Body.SessionSetupRes);
  1167. exiOut->V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK;
  1168. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.characters[0] = 0;
  1169. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.characters[1] = 20;
  1170. exiOut->V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 2;
  1171. exiOut->V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  1172. exiOut->V2G_Message.Body.SessionSetupRes.EVSETimeStamp = 123456789;
  1173. return 0;
  1174. }
  1175. static int serviceDetail1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1176. printf("EVSE side: serviceDetail called\n" );
  1177. printf("\tReceived data:\n");
  1178. printf("\tHeader SessionID=");
  1179. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  1180. printf("\t\t ServiceDetailID=%d\n",exiIn->V2G_Message.Body.ServiceDetailReq.ServiceID);
  1181. /* Prepare data for EV */
  1182. exiOut->V2G_Message_isUsed = 1u;
  1183. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1184. exiOut->V2G_Message.Body.ServiceDetailRes_isUsed= 1u;
  1185. init_iso1ServiceDetailResType(&exiOut->V2G_Message.Body.ServiceDetailRes);
  1186. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceID = 1234;
  1187. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList_isUsed = 1u;
  1188. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.arrayLen = 2;
  1189. /* Parameter Set 1*/
  1190. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].ParameterSetID = 1;
  1191. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.arrayLen = 2;
  1192. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.charactersLen = 8;
  1193. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[0] = 'P';
  1194. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[1] = 'r';
  1195. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[2] = 'o';
  1196. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[3] = 't';
  1197. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[4]= 'o';
  1198. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[5] = 'c';
  1199. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[6] = 'o';
  1200. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].Name.characters[7] = 'l';
  1201. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].intValue = 15119;
  1202. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[0].intValue_isUsed = 1u;
  1203. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.charactersLen = 4;
  1204. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[0] = 'N';
  1205. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[1] = 'a';
  1206. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[2] = 'm';
  1207. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].Name.characters[3] = 'e';
  1208. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue_isUsed = 1u;
  1209. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.charactersLen = 3;
  1210. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[0] = 'V';
  1211. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[1] = '2';
  1212. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[0].Parameter.array[1].stringValue.characters[2] = 'G';
  1213. /* Parameter Set 2 */
  1214. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].ParameterSetID = 2;
  1215. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.arrayLen = 1;
  1216. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.charactersLen = 7;
  1217. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[0] = 'C';
  1218. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[1] = 'h';
  1219. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[2] = 'a';
  1220. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[3] = 'n';
  1221. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[4] = 'n';
  1222. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[5] = 'e';
  1223. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].Name.characters[6] = 'l';
  1224. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue_isUsed = 1u;
  1225. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Value = 1234;
  1226. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Multiplier = 1;
  1227. exiOut->V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[1].Parameter.array[0].physicalValue.Value = 2;
  1228. exiOut->V2G_Message.Body.ServiceDetailRes.ResponseCode = iso1responseCodeType_OK;
  1229. return 0;
  1230. }
  1231. static int authorization1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1232. printf("EVSE: Authorization called\n" );
  1233. printf("\tReceived data:\n");
  1234. if(exiIn->V2G_Message.Body.AuthorizationReq.GenChallenge_isUsed) {
  1235. printf("\t\t\t GenChallenge=%d\n", exiIn->V2G_Message.Body.AuthorizationReq.GenChallenge.bytes[0]);
  1236. }
  1237. if(exiIn->V2G_Message.Body.AuthorizationReq.Id_isUsed ) {
  1238. printf("\t\t\t ID=%c%c%c\n", exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[0], exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[1], exiIn->V2G_Message.Body.AuthorizationReq.Id.characters[2]);
  1239. }
  1240. /* Prepare data for EV */
  1241. exiOut->V2G_Message_isUsed = 1u;
  1242. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1243. exiOut->V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  1244. init_iso1AuthorizationResType(&exiOut->V2G_Message.Body.AuthorizationRes);
  1245. exiOut->V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  1246. exiOut->V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  1247. return 0;
  1248. }
  1249. static int powerDelivery1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1250. printf("EVSE side: powerDelivery called\n" );
  1251. printf("\tReceived data:\n");
  1252. printf("\t\t ChargeProgress=%d\n", exiIn->V2G_Message.Body.PowerDeliveryReq.ChargeProgress);
  1253. printf("\t\t SAScheduleTupleID=%d\n", exiIn->V2G_Message.Body.PowerDeliveryReq.SAScheduleTupleID);
  1254. /* Prepare data for EV */
  1255. exiOut->V2G_Message_isUsed = 1u;
  1256. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1257. exiOut->V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  1258. init_iso1PowerDeliveryResType(&exiOut->V2G_Message.Body.PowerDeliveryRes);
  1259. exiOut->V2G_Message.Body.PowerDeliveryRes.ResponseCode = iso1responseCodeType_OK;
  1260. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus_isUsed = 1;
  1261. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  1262. exiOut->V2G_Message.Body.PowerDeliveryRes.EVSEStatus.NotificationMaxDelay=12;
  1263. return 0;
  1264. }
  1265. static int chargingStatus1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1266. printf("EVSE side: chargingStatus called\n" );
  1267. /* Prepare data for EV */
  1268. exiOut->V2G_Message_isUsed = 1u;
  1269. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1270. exiOut->V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  1271. init_iso1ChargingStatusResType(&exiOut->V2G_Message.Body.ChargingStatusRes);
  1272. exiOut->V2G_Message.Body.ChargingStatusRes.ResponseCode = iso1responseCodeType_OK;
  1273. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEID.characters[0]= 'A';
  1274. exiOut->V2G_Message.Body.ChargingStatusRes.EVSEID.charactersLen =1;
  1275. exiOut->V2G_Message.Body.ChargingStatusRes.ReceiptRequired = 1;
  1276. exiOut->V2G_Message.Body.ChargingStatusRes.ReceiptRequired_isUsed = 1;
  1277. return 0;
  1278. }
  1279. static int meteringReceipt1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1280. printf("EVSE side: meteringReceipt called\n" );
  1281. printf("\tReceived data:\n");
  1282. printf("\t\t ID=%c%c%c\n", exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[0], exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[1], exiIn->V2G_Message.Body.MeteringReceiptReq.Id.characters[2]);
  1283. printf("\t\t SAScheduleTupleID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.SAScheduleTupleID);
  1284. printf("\t\t SessionID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.SessionID.bytes[1]);
  1285. printf("\t\t MeterInfo.MeterStatus=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterStatus);
  1286. printf("\t\t MeterInfo.MeterID=%d\n", exiIn->V2G_Message.Body.MeteringReceiptReq.MeterInfo.MeterID.characters[0]);
  1287. /* Prepare data for EV */
  1288. exiOut->V2G_Message_isUsed = 1u;
  1289. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1290. exiOut->V2G_Message.Body.MeteringReceiptRes_isUsed = 1u;
  1291. init_iso1MeteringReceiptResType(&exiOut->V2G_Message.Body.MeteringReceiptRes);
  1292. exiOut->V2G_Message.Body.MeteringReceiptRes.ResponseCode = iso1responseCodeType_FAILED;
  1293. return 0;
  1294. }
  1295. static int sessionStop1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1296. printf("EVSE side: sessionStop called\n" );
  1297. printf("\tReceived data:\n");
  1298. printf("\tHeader SessionID=");
  1299. printBinaryArray(exiIn->V2G_Message.Header.SessionID.bytes, exiIn->V2G_Message.Header.SessionID.bytesLen);
  1300. printf("\t\t ChargingSession=%d\n", exiIn->V2G_Message.Body.SessionStopReq.ChargingSession);
  1301. /* Prepare data for EV */
  1302. exiOut->V2G_Message_isUsed = 1u;
  1303. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1304. exiOut->V2G_Message.Body.SessionStopRes_isUsed = 1u;
  1305. init_iso1SessionStopResType(&exiOut->V2G_Message.Body.SessionStopRes);
  1306. exiOut->V2G_Message.Body.SessionStopRes.ResponseCode = iso1responseCodeType_OK;
  1307. return 0;
  1308. }
  1309. static int cableCheck1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1310. printf("EVSE side: cableCheck called\n" );
  1311. /* Prepare data for EV */
  1312. exiOut->V2G_Message_isUsed = 1u;
  1313. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1314. exiOut->V2G_Message.Body.CableCheckRes_isUsed = 1u;
  1315. init_iso1CableCheckResType(&exiOut->V2G_Message.Body.CableCheckRes);
  1316. exiOut->V2G_Message.Body.CableCheckRes.ResponseCode = iso1responseCodeType_OK;
  1317. exiOut->V2G_Message.Body.CableCheckRes.DC_EVSEStatus.NotificationMaxDelay = 1234;
  1318. exiOut->V2G_Message.Body.CableCheckRes.DC_EVSEStatus.EVSENotification= iso1EVSENotificationType_ReNegotiation;
  1319. exiOut->V2G_Message.Body.CableCheckRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  1320. return 0;
  1321. }
  1322. static int preCharge1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1323. printf("EVSE side: preCharge called\n" );
  1324. printf("\tReceived data:\n");
  1325. printf("\t\t EVTargetCurrent=%d (%d)\n", exiIn->V2G_Message.Body.PreChargeReq.EVTargetCurrent.Value, exiIn->V2G_Message.Body.PreChargeReq.EVTargetCurrent.Multiplier);
  1326. printf("\t\t EVTargetVoltage=%d (%d)\n", exiIn->V2G_Message.Body.PreChargeReq.EVTargetVoltage.Value, exiIn->V2G_Message.Body.PreChargeReq.EVTargetVoltage.Multiplier);
  1327. /* Prepare data for EV */
  1328. exiOut->V2G_Message_isUsed = 1u;
  1329. init_iso1BodyType(&exiOut->V2G_Message.Body);
  1330. exiOut->V2G_Message.Body.PreChargeRes_isUsed = 1u;
  1331. init_iso1PreChargeResType(&exiOut->V2G_Message.Body.PreChargeRes);
  1332. exiOut->V2G_Message.Body.PreChargeRes.ResponseCode = iso1responseCodeType_OK;
  1333. exiOut->V2G_Message.Body.PreChargeRes.DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  1334. exiOut->V2G_Message.Body.PreChargeRes.DC_EVSEStatus.NotificationMaxDelay= 1234;
  1335. exiOut->V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Multiplier = 3;
  1336. exiOut->V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value= 456;
  1337. return 0;
  1338. }
  1339. static int create_response_message1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1340. int errn = ERROR_UNEXPECTED_REQUEST_MESSAGE;
  1341. /* create response message as EXI document */
  1342. if(exiIn->V2G_Message_isUsed) {
  1343. init_iso1EXIDocument(exiOut);
  1344. if (exiIn->V2G_Message.Body.SessionSetupReq_isUsed) {
  1345. errn = sessionSetup1(exiIn, exiOut);
  1346. } else if (exiIn->V2G_Message.Body.ServiceDetailReq_isUsed) {
  1347. errn = serviceDetail1(exiIn, exiOut);
  1348. /*} else if (exiIn->V2G_Message.Body.PaymentDetailsReq_isUsed) {
  1349. errn = paymentDetails1(exiIn, exiOut);*/
  1350. } else if (exiIn->V2G_Message.Body.AuthorizationReq_isUsed) {
  1351. errn = authorization1(exiIn, exiOut);
  1352. } else if (exiIn->V2G_Message.Body.PowerDeliveryReq_isUsed) {
  1353. errn = powerDelivery1(exiIn, exiOut);
  1354. } else if (exiIn->V2G_Message.Body.ChargingStatusReq_isUsed) {
  1355. errn = chargingStatus1(exiIn, exiOut);
  1356. } else if (exiIn->V2G_Message.Body.MeteringReceiptReq_isUsed) {
  1357. errn = meteringReceipt1(exiIn, exiOut);
  1358. } else if (exiIn->V2G_Message.Body.SessionStopReq_isUsed) {
  1359. errn = sessionStop1(exiIn, exiOut);
  1360. } else if (exiIn->V2G_Message.Body.CableCheckReq_isUsed) {
  1361. errn = cableCheck1(exiIn, exiOut);
  1362. } else if (exiIn->V2G_Message.Body.PreChargeReq_isUsed) {
  1363. errn = preCharge1(exiIn, exiOut);
  1364. }
  1365. }
  1366. return errn;
  1367. }
  1368. /* Adapt this to your system setup! */
  1369. /* In this situation EV and EVSE is the same party */
  1370. static int request_response1(struct iso1EXIDocument* exiIn, struct iso1EXIDocument* exiOut) {
  1371. int errn;
  1372. bitstream_t stream1;
  1373. bitstream_t stream2;
  1374. size_t pos1;
  1375. size_t pos2;
  1376. stream1.size = BUFFER_SIZE;
  1377. stream1.data = buffer1;
  1378. stream1.pos = &pos1;
  1379. stream2.size = BUFFER_SIZE;
  1380. stream2.data = buffer2;
  1381. stream2.pos = &pos2;
  1382. /* EV side */
  1383. errn = serialize1EXI2Stream(exiIn, &stream1);
  1384. /* --> Start of EVSE side */
  1385. /* deserialize request message */
  1386. if (errn == 0) {
  1387. errn = deserialize1Stream2EXI(&stream1, exiOut);
  1388. }
  1389. /* create response message */
  1390. if (errn == 0) {
  1391. errn = create_response_message1(exiOut, exiIn);
  1392. }
  1393. /* serialize response message */
  1394. if (errn == 0) {
  1395. errn = serialize1EXI2Stream(exiIn, &stream2);
  1396. }
  1397. /* <-- End of EVSE side */
  1398. /* EV side */
  1399. /* deserialize response message */
  1400. if (errn == 0) {
  1401. errn = deserialize1Stream2EXI(&stream2, exiOut);
  1402. }
  1403. return errn;
  1404. }
  1405. static int charging1()
  1406. {
  1407. int errn = 0;
  1408. int i, j;
  1409. struct iso1EXIDocument exiIn;
  1410. struct iso1EXIDocument exiOut;
  1411. struct iso1ServiceDetailResType serviceDetailRes;
  1412. struct iso1PaymentDetailsResType paymentDetailsRes;
  1413. /* setup header information */
  1414. init_iso1EXIDocument(&exiIn);
  1415. exiIn.V2G_Message_isUsed = 1u;
  1416. init_iso1MessageHeaderType(&exiIn.V2G_Message.Header);
  1417. exiIn.V2G_Message.Header.SessionID.bytes[0] = 0; /* sessionID is always '0' at the beginning (the response contains the valid sessionID)*/
  1418. exiIn.V2G_Message.Header.SessionID.bytes[1] = 0;
  1419. exiIn.V2G_Message.Header.SessionID.bytes[2] = 0;
  1420. exiIn.V2G_Message.Header.SessionID.bytes[3] = 0;
  1421. exiIn.V2G_Message.Header.SessionID.bytes[4] = 0;
  1422. exiIn.V2G_Message.Header.SessionID.bytes[5] = 0;
  1423. exiIn.V2G_Message.Header.SessionID.bytes[6] = 0;
  1424. exiIn.V2G_Message.Header.SessionID.bytes[7] = 0;
  1425. exiIn.V2G_Message.Header.SessionID.bytesLen = 8;
  1426. exiIn.V2G_Message.Header.Signature_isUsed = 0u;
  1427. /************************
  1428. * sessionSetup *
  1429. ************************/
  1430. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1431. exiIn.V2G_Message.Body.SessionSetupReq_isUsed = 1u;
  1432. init_iso1SessionSetupReqType(&exiIn.V2G_Message.Body.SessionSetupReq);
  1433. exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytesLen = 1;
  1434. exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0] = 10;
  1435. printf("EV side: call EVSE sessionSetup");
  1436. errn = request_response1(&exiIn, &exiOut);
  1437. if(errn == 0) {
  1438. /* check, if this is the right response message */
  1439. if(exiOut.V2G_Message.Body.SessionSetupRes_isUsed) {
  1440. /* show results of EVSEs answer message */
  1441. printf("EV side: received response message from EVSE\n");
  1442. printf("\tHeader SessionID=");
  1443. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1444. printf("\tResponseCode=%d\n", exiOut.V2G_Message.Body.SessionSetupRes.ResponseCode);
  1445. printf("\tEVSEID=%d\n", exiOut.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]);
  1446. printf("\tEVSETimeStamp=%li\n", (long int)exiOut.V2G_Message.Body.SessionSetupRes.EVSETimeStamp);
  1447. } else {
  1448. errn = ERROR_UNEXPECTED_SESSION_SETUP_RESP_MESSAGE;
  1449. return errn;
  1450. }
  1451. } else {
  1452. return errn;
  1453. }
  1454. /*********************************
  1455. * ServiceDetails *
  1456. *********************************/
  1457. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1458. exiIn.V2G_Message.Body.ServiceDetailReq_isUsed = 1u;
  1459. init_iso1ServiceDetailReqType(&exiIn.V2G_Message.Body.ServiceDetailReq);
  1460. exiIn.V2G_Message.Body.ServiceDetailReq.ServiceID = 22; /* Value Added Server ID */
  1461. printf("EV side: call EVSE ServiceDetail \n");
  1462. errn = request_response1(&exiIn, &exiOut);
  1463. if(errn == 0) {
  1464. /* check, if this is the right response message */
  1465. if(exiOut.V2G_Message.Body.ServiceDetailRes_isUsed) {
  1466. serviceDetailRes = exiOut.V2G_Message.Body.ServiceDetailRes;
  1467. /* show results of EVSEs answer message */
  1468. printf("EV side: received response message from EVSE\n");
  1469. printf("\tHeader SessionID=");
  1470. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1471. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode);
  1472. printf("\t ServiceID=%d\n", exiOut.V2G_Message.Body.ServiceDetailRes.ServiceID);
  1473. if(serviceDetailRes.ServiceParameterList_isUsed) {
  1474. printf("\t\tLength=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.arrayLen );/*TEST*/
  1475. for(i=0; i<serviceDetailRes.ServiceParameterList.ParameterSet.arrayLen; i++)
  1476. {
  1477. printf("\t\tServiceSetID=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.array[i].ParameterSetID);
  1478. printf("\t\tParameters=%d\n", serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.arrayLen);
  1479. for(j=0; j<serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.arrayLen; j++)
  1480. {
  1481. printf("\t\t\t %d: ParameterName=", j+1);
  1482. printASCIIString(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].Name.characters, exiOut.V2G_Message.Body.ServiceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].Name.charactersLen);
  1483. /*if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].shortValue_isUsed == 1u) {
  1484. printf("\t\t\t %d: StringValue=", j+1);
  1485. printASCIIString(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].stringValue.characters, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].stringValue.charactersLen);
  1486. } else if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].intValue_isUsed == 1u) {
  1487. printf("\t\t\t %d: IntValue=%d\n", j+1, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].intValue);
  1488. } else if(serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue_isUsed == 1u) {
  1489. printf("\t\t\t %d: PhysicalValue=%d (%d)\n", j+1, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue.Value, serviceDetailRes.ServiceParameterList.ParameterSet.array[i].Parameter.array[j].physicalValue.Multiplier);
  1490. }*/
  1491. }
  1492. }
  1493. }
  1494. } else {
  1495. errn = ERROR_UNEXPECTED_SERVICE_DETAILS_RESP_MESSAGE;
  1496. return errn;
  1497. }
  1498. } else {
  1499. return errn;
  1500. }
  1501. /*******************************************
  1502. * Authorization *
  1503. *******************************************/
  1504. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1505. exiIn.V2G_Message.Body.AuthorizationReq_isUsed = 1u;
  1506. init_iso1AuthorizationReqType(&exiIn.V2G_Message.Body.AuthorizationReq);
  1507. copyBytes(paymentDetailsRes.GenChallenge.bytes, paymentDetailsRes.GenChallenge.bytesLen, exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge.bytes);
  1508. exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge.bytesLen = paymentDetailsRes.GenChallenge.bytesLen;
  1509. exiIn.V2G_Message.Body.AuthorizationReq.GenChallenge_isUsed = 1u; /* no challenge needed here*/
  1510. exiIn.V2G_Message.Body.AuthorizationReq.Id_isUsed = 1u; /* no signature needed here */
  1511. exiIn.V2G_Message.Body.AuthorizationReq.Id.charactersLen = 3;
  1512. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[0] = 'I';
  1513. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[1] = 'd';
  1514. exiIn.V2G_Message.Body.AuthorizationReq.Id.characters[2] = '2';
  1515. printf("EV side: call EVSE Authorization \n");
  1516. errn = request_response1(&exiIn, &exiOut);
  1517. if(errn == 0) {
  1518. /* check, if this is the right response message */
  1519. if(exiOut.V2G_Message.Body.AuthorizationRes_isUsed) {
  1520. /* show results of EVSEs answer message */
  1521. printf("EV side: received response message from EVSE\n");
  1522. printf("\tHeader SessionID=");
  1523. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1524. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.AuthorizationRes.ResponseCode);
  1525. if(exiOut.V2G_Message.Body.AuthorizationRes.EVSEProcessing == iso1EVSEProcessingType_Finished) {
  1526. printf("\t EVSEProcessing=Finished\n");
  1527. }
  1528. } else {
  1529. errn = ERROR_UNEXPECTED_AUTHORIZATION_RESP_MESSAGE;
  1530. return errn;
  1531. }
  1532. } else {
  1533. return errn;
  1534. }
  1535. /*****************************
  1536. * cableCheck *
  1537. *****************************/
  1538. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1539. exiIn.V2G_Message.Body.CableCheckReq_isUsed = 1u;
  1540. /*init_v2gCableCheckReqType(&exiIn.V2G_Message.Body.CableCheckReq);*/
  1541. printf("EV side: call EVSE cableCheck \n");
  1542. errn = request_response1(&exiIn, &exiOut);
  1543. if(errn == 0) {
  1544. /* check, if this is the right response message */
  1545. if(exiOut.V2G_Message.Body.CableCheckRes_isUsed) {
  1546. /* show results of EVSEs answer message */
  1547. printf("EV side: received response message from EVSE\n");
  1548. printf("\tHeader SessionID=");
  1549. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1550. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.CableCheckRes.ResponseCode);
  1551. if(exiOut.V2G_Message.Body.CableCheckRes.EVSEProcessing==iso1EVSEProcessingType_Finished) {
  1552. printf("\tEVSEProcessing=Finished\n");
  1553. }
  1554. printEVSEStatus1(&(exiOut.V2G_Message.Body.CableCheckRes.DC_EVSEStatus));
  1555. } else {
  1556. errn = ERROR_UNEXPECTED_CABLE_CHECK_RESP_MESSAGE;
  1557. return errn;
  1558. }
  1559. } else {
  1560. return errn;
  1561. }
  1562. /*****************************
  1563. * preCharge *
  1564. *****************************/
  1565. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1566. exiIn.V2G_Message.Body.PreChargeReq_isUsed = 1u;
  1567. init_iso1PreChargeReqType(&exiIn.V2G_Message.Body.PreChargeReq);
  1568. exiIn.V2G_Message.Body.PreChargeReq.EVTargetCurrent.Multiplier = 1;
  1569. exiIn.V2G_Message.Body.PreChargeReq.EVTargetCurrent.Value = 234;
  1570. exiIn.V2G_Message.Body.PreChargeReq.EVTargetVoltage.Multiplier = 1;
  1571. exiIn.V2G_Message.Body.PreChargeReq.EVTargetVoltage.Value = 100;
  1572. printf("EV side: call EVSE preCharge \n");
  1573. errn = request_response1(&exiIn, &exiOut);
  1574. if(errn == 0) {
  1575. /* check, if this is the right response message */
  1576. if(exiOut.V2G_Message.Body.PreChargeRes_isUsed) {
  1577. /* show results of EVSEs answer message */
  1578. printf("EV side: received response message from EVSE\n");
  1579. printf("\tHeader SessionID=");
  1580. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1581. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.PreChargeRes.ResponseCode);
  1582. printEVSEStatus1(&exiOut.V2G_Message.Body.PreChargeRes.DC_EVSEStatus);
  1583. printf("\tEVSEPresentVoltage=%d (%d %d)\n", exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value, exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Value, exiOut.V2G_Message.Body.PreChargeRes.EVSEPresentVoltage.Multiplier);
  1584. } else {
  1585. errn = ERROR_UNEXPECTED_PRE_CHARGE_RESP_MESSAGE;
  1586. return errn;
  1587. }
  1588. } else {
  1589. return errn;
  1590. }
  1591. /*********************************
  1592. * PowerDelivery *
  1593. *********************************/
  1594. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1595. exiIn.V2G_Message.Body.PowerDeliveryReq_isUsed = 1u;
  1596. init_iso1PowerDeliveryReqType(&exiIn.V2G_Message.Body.PowerDeliveryReq);
  1597. exiIn.V2G_Message.Body.PowerDeliveryReq.ChargeProgress = iso1chargeProgressType_Start;
  1598. exiIn.V2G_Message.Body.PowerDeliveryReq.SAScheduleTupleID = exiOut.V2G_Message.Body.ChargeParameterDiscoveryRes.SAScheduleList.SAScheduleTuple.array[0].SAScheduleTupleID;
  1599. printf("EV side: call EVSE powerDelivery \n");
  1600. errn = request_response1(&exiIn, &exiOut);
  1601. if(errn == 0) {
  1602. /* check, if this is the right response message */
  1603. if(exiOut.V2G_Message.Body.PowerDeliveryRes_isUsed) {
  1604. /* show results of EVSEs answer message */
  1605. printf("EV side: received response message from EVSE\n");
  1606. printf("\tHeader SessionID=");
  1607. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1608. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.PowerDeliveryRes.ResponseCode);
  1609. /*printACEVSEStatus(&(exiOut.V2G_Message.Body.PowerDeliveryRes.AC_EVSEStatus));*/
  1610. } else {
  1611. errn = ERROR_UNEXPECTED_POWER_DELIVERY_RESP_MESSAGE;
  1612. return errn;
  1613. }
  1614. } else {
  1615. return errn;
  1616. }
  1617. /*********************************
  1618. * Setup data for chargingStatus *
  1619. *********************************/
  1620. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1621. exiIn.V2G_Message.Body.ChargingStatusReq_isUsed = 1u;
  1622. init_iso1ChargingStatusReqType(&exiIn.V2G_Message.Body.ChargingStatusReq);
  1623. printf("EV side: call EVSE chargingStatus \n");
  1624. errn = request_response1(&exiIn, &exiOut);
  1625. if(errn == 0) {
  1626. /* check, if this is the right response message */
  1627. if(exiOut.V2G_Message.Body.ChargingStatusRes_isUsed) {
  1628. /* show results of EVSEs answer message */
  1629. printf("EV side: received response message from EVSE\n");
  1630. printf("\tHeader SessionID=");
  1631. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1632. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.ResponseCode);
  1633. /*printACEVSEStatus(&(exiOut.V2G_Message.Body.ChargingStatusRes.AC_EVSEStatus));
  1634. printf("\tReceiptRequired=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.ReceiptRequired);
  1635. printf("\tEVSEID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.EVSEID.characters[0]);
  1636. printf("\tSAScheduleTupleID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.SAScheduleTupleID);
  1637. printf("\tEVSEMaxCurrent=%d (%d %d)\n", exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Value, exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Unit, exiOut.V2G_Message.Body.ChargingStatusRes.EVSEMaxCurrent.Multiplier);
  1638. printf("\tisused.MeterInfo=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo_isUsed);
  1639. printf("\t\tMeterInfo.MeterID=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterID.characters[0]);
  1640. printf("\t\tMeterInfo.MeterReading.Value=%li\n", (long int)exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterReading);
  1641. printf("\t\tMeterInfo.MeterStatus=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.MeterStatus);
  1642. printf("\t\tMeterInfo.TMeter=%li\n", (long int)exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.TMeter);
  1643. printf("\t\tMeterInfo.SigMeterReading.data=%d\n", exiOut.V2G_Message.Body.ChargingStatusRes.MeterInfo.SigMeterReading.bytes[0]);*/
  1644. } else {
  1645. errn = ERROR_UNEXPECTED_CHARGING_STATUS_RESP_MESSAGE;
  1646. return errn;
  1647. }
  1648. } else {
  1649. return errn;
  1650. }
  1651. /***********************************
  1652. * SessionStop *
  1653. ***********************************/
  1654. init_iso1BodyType(&exiIn.V2G_Message.Body);
  1655. exiIn.V2G_Message.Body.SessionStopReq_isUsed = 1u;
  1656. init_iso1SessionStopReqType(&exiIn.V2G_Message.Body.SessionStopReq);
  1657. exiIn.V2G_Message.Body.SessionStopReq.ChargingSession = iso1chargingSessionType_Pause;
  1658. printf("EV side: call EVSE stopSession \n");
  1659. errn = request_response1(&exiIn, &exiOut);
  1660. if(errn == 0) {
  1661. /* check, if this is the right response message */
  1662. if(exiOut.V2G_Message.Body.SessionStopRes_isUsed) {
  1663. /* show results of EVSEs answer message */
  1664. printf("EV side: received response message from EVSE\n");
  1665. printf("\tHeader SessionID=");
  1666. printBinaryArray(exiOut.V2G_Message.Header.SessionID.bytes, exiOut.V2G_Message.Header.SessionID.bytesLen);
  1667. printf("\t ResponseCode=%d\n", exiOut.V2G_Message.Body.SessionStopRes.ResponseCode);
  1668. } else {
  1669. errn = ERROR_UNEXPECTED_SESSION_STOP_RESP_MESSAGE;
  1670. return errn;
  1671. }
  1672. } else {
  1673. return errn;
  1674. }
  1675. return errn;
  1676. }
  1677. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  1678. /*===========================================================================
  1679. FUNCTION: din_test_decode_SessionSetupReq
  1680. DESCRIPTION:
  1681. The original V2GTP EXI stream is as below.
  1682. SIZE: 20 (Bytes, DEC)
  1683. TOTAL: 01fe80010000000c809a004011d0111d5d155800
  1684. HEADER (HEX): 01FE80010000000C
  1685. EXI (HEX): 809A004011D0111D5D155800
  1686. PRE-CONDITION:
  1687. INPUT:
  1688. OUTPUT:
  1689. GLOBAL VARIABLES:
  1690. =============================================================================*/
  1691. int din_test_decode_SessionSetupReq()
  1692. {
  1693. int errn = 0;
  1694. struct dinEXIDocument exiDin;
  1695. bitstream_t stream;
  1696. uint8_t buffer[] = {0x80, 0x9A, 0x00, 0x40, 0x11, 0xD0, 0x11, 0x1D, 0x5D, 0x15, 0x58, 0x00};
  1697. size_t pos = 0;
  1698. stream.size = BUFFER_SIZE;
  1699. stream.data = buffer;
  1700. stream.pos = &pos;
  1701. errn = decode_dinExiDocument(&stream, &exiDin);
  1702. if(errn != 0)
  1703. {
  1704. printf("\n\n[SessionSetupReq] DIN test error %d!\n", errn);
  1705. return errn;
  1706. }
  1707. else if (pos != 0x0C) //[CAUTION] length
  1708. {
  1709. printf("\n\n[SessionSetupReq] DIN warning. not all bytes read! (pos = %ld)\n", pos);
  1710. errn = -1;
  1711. return errn;
  1712. }
  1713. else
  1714. {
  1715. unsigned int tmp = 0;
  1716. tmp = exiDin.V2G_Message.Body.SessionSetupReq_isUsed;
  1717. if (tmp == 1u)
  1718. {
  1719. printf("\n ---------- [din_test_decode_SessionSetupReq] ----------\n \
  1720. \t - SessionSetupReq is decoded OK!\n\
  1721. \t - SessionSetupReq_isUsed = %d\
  1722. \n", tmp);
  1723. }
  1724. else
  1725. {
  1726. printf("[ERROR][din_test_decode_SessionSetupReq] SessionSetupReq_isUsed = %d\n", tmp);
  1727. }
  1728. }
  1729. return errn;
  1730. }
  1731. /*===========================================================================
  1732. FUNCTION: din_test_ServiceDiscoveryReq
  1733. DESCRIPTION:
  1734. The original V2GTP EXI stream is as below.
  1735. SIZE: 15 (Bytes, DEC)
  1736. TOTAL: 01fe800100000007809a0040119400
  1737. HEADER (HEX): 01FE800100000007
  1738. EXI (HEX): 809A0040119400
  1739. PRE-CONDITION:
  1740. INPUT:
  1741. OUTPUT:
  1742. GLOBAL VARIABLES:
  1743. =============================================================================*/
  1744. int din_test_decode_ServiceDiscoveryReq()
  1745. {
  1746. int errn = 0;
  1747. struct dinEXIDocument exiDin;
  1748. bitstream_t stream;
  1749. uint8_t buffer[] = {0x80, 0x9A, 0x00, 0x40, 0x11, 0x94, 0x00};
  1750. size_t pos = 0;
  1751. stream.size = BUFFER_SIZE;
  1752. stream.data = buffer;
  1753. stream.pos = &pos;
  1754. errn = decode_dinExiDocument(&stream, &exiDin);
  1755. if(errn != 0)
  1756. {
  1757. printf("\n\n[ServiceDiscoveryReq] DIN test error %d!\n", errn);
  1758. return errn;
  1759. }
  1760. else if (pos != 0x07) //[CAUTION] length
  1761. {
  1762. printf("\n\n[ServiceDiscoveryReq] DIN warning. not all bytes read! (pos = %ld)\n", pos);
  1763. errn = -1;
  1764. return errn;
  1765. }
  1766. else
  1767. {
  1768. unsigned int tmp = 0;
  1769. tmp = exiDin.V2G_Message.Body.ServiceDiscoveryReq_isUsed;
  1770. if (tmp == 1u)
  1771. {
  1772. printf("\n ---------- [din_test_decode_ServiceDiscoveryReq] ----------\n\
  1773. \t - ServiceDiscoveryReq is decoded OK!\n\
  1774. \t - ServiceDiscoveryReq_isUsed = %d\n", tmp);
  1775. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&exiDin);
  1776. }
  1777. else
  1778. {
  1779. printf("[ERROR][din_test_decode_ServiceDiscoveryReq] ServiceDiscoveryReq_isUsed = %d\n", tmp);
  1780. }
  1781. }
  1782. return errn;
  1783. }
  1784. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  1785. static int din_test()
  1786. {
  1787. int errn = 0;
  1788. struct dinEXIDocument exiDin1;
  1789. struct dinEXIDocument exiDin2;
  1790. bitstream_t stream1;
  1791. bitstream_t stream2;
  1792. size_t pos1 = 0;
  1793. size_t pos2 = 0;
  1794. stream1.size = BUFFER_SIZE;
  1795. stream1.data = buffer1;
  1796. stream1.pos = &pos1;
  1797. stream2.size = BUFFER_SIZE;
  1798. stream2.data = buffer2;
  1799. stream2.pos = &pos2;
  1800. errn = din_test_decode_SessionSetupReq(); //added by Joseph
  1801. errn = din_test_decode_ServiceDiscoveryReq(); //added by Joseph
  1802. /* SetupSessionReq */
  1803. /* BMW: 80 9A 00 11 D0 20 00 03 C1 FC 30 00 43 F8 00 */
  1804. buffer1[0] = 0x80;
  1805. buffer1[1] = 0x9A;
  1806. buffer1[2] = 0x00;
  1807. buffer1[3] = 0x11;
  1808. buffer1[4] = 0xD0;
  1809. buffer1[5] = 0x20;
  1810. buffer1[6] = 0x00;
  1811. buffer1[7] = 0x03;
  1812. buffer1[8] = 0xC1;
  1813. buffer1[9] = 0xFC;
  1814. buffer1[10] = 0x30;
  1815. buffer1[11] = 0x00;
  1816. buffer1[12] = 0x43;
  1817. buffer1[13] = 0xF8;
  1818. buffer1[14] = 0x00;
  1819. errn = decode_dinExiDocument(&stream1, &exiDin1);
  1820. printf("\n\tSessionSetupReq_isUsed = %d\n", exiDin1.V2G_Message.Body.SessionSetupReq_isUsed);
  1821. printf("\t\tEVCCID Length= %d\n", exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytesLen);
  1822. printf("\t\tEVCCID = %02X%02X%02X%02X%02X%02X%02X%02X\n",
  1823. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0],
  1824. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[1],
  1825. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[2],
  1826. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[3],
  1827. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[4],
  1828. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[5],
  1829. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[6],
  1830. exiDin1.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[7]
  1831. );
  1832. if(errn != 0)
  1833. {
  1834. printf("\n\nDIN test error %d!\n", errn);
  1835. return errn;
  1836. }
  1837. else if (pos1 != 15)
  1838. {
  1839. printf("\n\nDIN warning. not all bytes read!\n");
  1840. errn = -1;
  1841. return errn;
  1842. }
  1843. /* SetupSessionReq */
  1844. /* Chevy: 80 9A 02 00 00 00 00 00 00 00 00 11 D0 18 00 60 8C 44 09 94 00 */
  1845. buffer2[0] = 0x80;
  1846. buffer2[1] = 0x9A;
  1847. buffer2[2] = 0x02;
  1848. buffer2[3] = 0x00;
  1849. buffer2[4] = 0x00;
  1850. buffer2[5] = 0x00;
  1851. buffer2[6] = 0x00;
  1852. buffer2[7] = 0x00;
  1853. buffer2[8] = 0x00;
  1854. buffer2[9] = 0x00;
  1855. buffer2[10] = 0x00;
  1856. buffer2[11] = 0x11;
  1857. buffer2[12] = 0xD0;
  1858. buffer2[13] = 0x18;
  1859. buffer2[14] = 0x00;
  1860. buffer2[15] = 0x60;
  1861. buffer2[16] = 0x8C;
  1862. buffer2[17] = 0x44;
  1863. buffer2[18] = 0x09;
  1864. buffer2[19] = 0x94;
  1865. buffer2[20] = 0x00;
  1866. errn = decode_dinExiDocument(&stream2, &exiDin2);
  1867. if(errn != 0) {
  1868. printf("\n\nDIN test error %d!\n", errn);
  1869. return errn;
  1870. } else if (pos2 != 21) {
  1871. printf("\n\nDIN warning. not all bytes read!\n");
  1872. errn = -1;
  1873. return errn;
  1874. }
  1875. /* sessionStopReq */
  1876. pos2 = 0; /* reset position */
  1877. /* V: 0x80, 0x9a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x91, 0xf0 */
  1878. buffer2[0] = 0x80;
  1879. buffer2[1] = 0x9a;
  1880. buffer2[2] = 0x02;
  1881. buffer2[3] = 0x00;
  1882. buffer2[4] = 0x00;
  1883. buffer2[5] = 0x00;
  1884. buffer2[6] = 0x00;
  1885. buffer2[7] = 0x00;
  1886. buffer2[8] = 0x00;
  1887. buffer2[9] = 0x00;
  1888. buffer2[10] = 0x03;
  1889. buffer2[11] = 0x91;
  1890. buffer2[12] = 0xf0;
  1891. errn = decode_dinExiDocument(&stream2, &exiDin2);
  1892. if(errn != 0) {
  1893. printf("\n\nDIN test error %d!\n", errn);
  1894. return errn;
  1895. } else if (pos2 != 13) {
  1896. printf("\n\nDIN warning. not all bytes read!\n");
  1897. errn = -1;
  1898. return errn;
  1899. } else if(exiDin2.V2G_Message_isUsed == 0 || exiDin2.V2G_Message.Body.SessionStopReq_isUsed == 0) {
  1900. printf("\n\nDIN warning. no sessionStopReq message!\n");
  1901. errn = -1;
  1902. return errn;
  1903. }
  1904. if(errn == 0) {
  1905. printf("DIN test passed\n");
  1906. } else {
  1907. printf("DIN test error %d!\n", errn);
  1908. }
  1909. return errn;
  1910. }
  1911. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  1912. #if DEPLOY_XMLDSIG_CODEC == SUPPORT_YES
  1913. #if DEPLOY_ISO_CODEC_FRAGMENT == SUPPORT_YES
  1914. static int xmldsig_test() {
  1915. int errn = 0, i;
  1916. bitstream_t stream1;
  1917. size_t pos1 = 0;
  1918. stream1.size = BUFFER_SIZE;
  1919. stream1.data = buffer1;
  1920. stream1.pos = &pos1;
  1921. bitstream_t stream2;
  1922. size_t pos2 = 0;
  1923. stream2.size = BUFFER_SIZE;
  1924. stream2.data = buffer2;
  1925. stream2.pos = &pos2;
  1926. struct iso2EXIFragment exiV2G_AR;
  1927. struct xmldsigEXIFragment exiXMLDSIG_SI;
  1928. int sizeIsoStream1 = 25;
  1929. int isoStream1[] = {0x80, 0x04, 0x01, 0x52, 0x51, 0x0C, 0x40, 0x82, 0x9B, 0x7B, 0x6B, 0x29, 0x02, 0x93, 0x0B, 0x73, 0x23, 0x7B, 0x69, 0x02, 0x23, 0x0B, 0xA3, 0x09, 0xE8};
  1930. int sizeIsoStream2 = 209;
  1931. int isoStream2[] = {0x80, 0x81, 0x12, 0xB4, 0x3A, 0x3A, 0x38, 0x1D, 0x17, 0x97, 0xBB, 0xBB, 0xBB, 0x97, 0x3B, 0x99, 0x97, 0x37, 0xB9, 0x33, 0x97, 0xAA, 0x29, 0x17, 0xB1, 0xB0, 0xB7, 0x37, 0xB7, 0x34, 0xB1, 0xB0, 0xB6, 0x16, 0xB2, 0xBC, 0x34, 0x97, 0xA1, 0xAB, 0x43, 0xA3, 0xA3, 0x81, 0xD1, 0x79, 0x7B, 0xBB, 0xBB, 0xB9, 0x73, 0xB9, 0x99, 0x73, 0x7B, 0x93, 0x39, 0x79, 0x91, 0x81, 0x81, 0x89, 0x79, 0x81, 0xA1, 0x7B, 0xC3, 0x6B, 0x63, 0x23, 0x9B, 0x4B, 0x39, 0x6B, 0x6B, 0x7B, 0x93, 0x29, 0x1B, 0x2B, 0x1B, 0x23, 0x9B, 0x09, 0x6B, 0x9B, 0x43, 0x09, 0x91, 0xA9, 0xB2, 0x20, 0x62, 0x34, 0x94, 0x43, 0x10, 0x25, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x33, 0x2E, 0x6F, 0x72, 0x67, 0x2F, 0x54, 0x52, 0x2F, 0x63, 0x61, 0x6E, 0x6F, 0x6E, 0x69, 0x63, 0x61, 0x6C, 0x2D, 0x65, 0x78, 0x69, 0x2F, 0x48, 0x52, 0xD0, 0xE8, 0xE8, 0xE0, 0x74, 0x5E, 0x5E, 0xEE, 0xEE, 0xEE, 0x5C, 0xEE, 0x66, 0x5C, 0xDE, 0xE4, 0xCE, 0x5E, 0x64, 0x60, 0x60, 0x62, 0x5E, 0x60, 0x68, 0x5E, 0xF0, 0xDA, 0xD8, 0xCA, 0xDC, 0xC6, 0x46, 0xE6, 0xD0, 0xC2, 0x64, 0x6A, 0x6C, 0x84, 0x1A, 0x36, 0xBC, 0x07, 0xA0, 0x0C, 0xB7, 0xDC, 0xAD, 0x66, 0x2F, 0x30, 0x88, 0xA6, 0x0A, 0x3D, 0x6A, 0x99, 0x43, 0x1F, 0x81, 0xC1, 0x22, 0xC2, 0xE9, 0xF1, 0x67, 0x8E, 0xF5, 0x31, 0xE9, 0x55, 0x23, 0x70};
  1932. uint8_t digestValue[] = {0xD1, 0xB5, 0xE0, 0x3D, 0x00, 0x65, 0xBE, 0xE5, 0x6B, 0x31, 0x79, 0x84, 0x45, 0x30, 0x51, 0xEB, 0x54, 0xCA, 0x18, 0xFC, 0x0E, 0x09, 0x16, 0x17, 0x4F, 0x8B, 0x3C, 0x77, 0xA9, 0x8F, 0x4A, 0xA9}; /* 32 Bytes */
  1933. /*
  1934. <v2gci_b:AuthorizationReq xmlns:v2gci_b="urn:iso:15118:2:2013:MsgBody" v2gci_b:Id="ID1">
  1935. <v2gci_b:GenChallenge>U29tZSBSYW5kb20gRGF0YQ==</v2gci_b:GenChallenge>
  1936. </v2gci_b:AuthorizationReq>
  1937. */
  1938. init_iso2EXIFragment(&exiV2G_AR);
  1939. exiV2G_AR.AuthorizationReq_isUsed = 1u;
  1940. init_iso2AuthorizationReqType(&exiV2G_AR.AuthorizationReq);
  1941. exiV2G_AR.AuthorizationReq.Id_isUsed = 1;
  1942. exiV2G_AR.AuthorizationReq.Id.charactersLen = 3;
  1943. exiV2G_AR.AuthorizationReq.Id.characters[0] = 'I';
  1944. exiV2G_AR.AuthorizationReq.Id.characters[1] = 'D';
  1945. exiV2G_AR.AuthorizationReq.Id.characters[2] = '1';
  1946. exiV2G_AR.AuthorizationReq.GenChallenge_isUsed = 1;
  1947. /* base64 U29tZSBSYW5kb20gRGF0YQ== */
  1948. exiV2G_AR.AuthorizationReq.GenChallenge.bytesLen = 16;
  1949. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[0] = 0x53;
  1950. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[1] = 0x6F;
  1951. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[2] = 0x6D;
  1952. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[3] = 0x65;
  1953. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[4] = 0x20;
  1954. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[5] = 0x52;
  1955. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[6] = 0x61;
  1956. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[7] = 0x6E;
  1957. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[8] = 0x64;
  1958. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[9] = 0x6F;
  1959. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[10] = 0x6D;
  1960. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[11] = 0x20;
  1961. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[12] = 0x44;
  1962. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[13] = 0x61;
  1963. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[14] = 0x74;
  1964. exiV2G_AR.AuthorizationReq.GenChallenge.bytes[15] = 0x61;
  1965. /* encode fragment with ISO schema */
  1966. errn = encode_iso2ExiFragment(&stream1, &exiV2G_AR);
  1967. if((*stream1.pos) != sizeIsoStream1) {
  1968. errn = -1;
  1969. printf("EXI1 stream length does not match !\n");
  1970. return errn;
  1971. } else {
  1972. for(i=0; i<sizeIsoStream1; i++) {
  1973. if(stream1.data[i] != isoStream1[i]) {
  1974. errn = -1;
  1975. printf("EXI1 stream does not match at position %d !\n", i);
  1976. return errn;
  1977. }
  1978. }
  1979. }
  1980. /* TODO Create Hash for stream 1 etc ... */
  1981. /* SHA-256 is "0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=" */
  1982. /*
  1983. <xmlsig:SignedInfo xmlns:xmlsig="http://www.w3.org/2000/09/xmldsig#" >
  1984. <xmlsig:CanonicalizationMethod Algorithm="http://www.w3.org/TR/canonical-exi/"/>
  1985. <xmlsig:SignatureMethod
  1986. Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
  1987. <xmlsig:Reference URI="#ID1">
  1988. <xmlsig:Transforms>
  1989. <xmlsig:Transform Algorithm="http://www.w3.org/TR/canonical-exi/"/>
  1990. </xmlsig:Transforms>
  1991. <xmlsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
  1992. <xmlsig:DigestValue>0bXgPQBlvuVrMXmERTBR61TK
  1993. GPwOCRYXT4s8d6mPSqk=</xmlsig:DigestValue>
  1994. </xmlsig:Reference>
  1995. </xmlsig:SignedInfo>
  1996. */
  1997. /* encode SignedInfo element with xmldsig schema */
  1998. const char arrayCanonicalEXI[35] = {"http://www.w3.org/TR/canonical-exi/"};
  1999. const char arrayxmldsigSHA256[51] = {"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"};
  2000. const char arrayxmlencSHA256[39] = {"http://www.w3.org/2001/04/xmlenc#sha256"};
  2001. init_xmldsigEXIFragment(&exiXMLDSIG_SI);
  2002. exiXMLDSIG_SI.SignedInfo_isUsed = 1;
  2003. init_xmldsigSignedInfoType(&exiXMLDSIG_SI.SignedInfo);
  2004. {
  2005. init_xmldsigCanonicalizationMethodType(&exiXMLDSIG_SI.SignedInfo.CanonicalizationMethod);
  2006. exiXMLDSIG_SI.SignedInfo.CanonicalizationMethod.Algorithm.charactersLen = 35;
  2007. strncpy(exiXMLDSIG_SI.SignedInfo.CanonicalizationMethod.Algorithm.characters, arrayCanonicalEXI, 35);
  2008. exiXMLDSIG_SI.SignedInfo.SignatureMethod.HMACOutputLength_isUsed = 0;
  2009. exiXMLDSIG_SI.SignedInfo.SignatureMethod.Algorithm.charactersLen = 51;
  2010. strncpy(exiXMLDSIG_SI.SignedInfo.SignatureMethod.Algorithm.characters, arrayxmldsigSHA256, 51);
  2011. exiXMLDSIG_SI.SignedInfo.Reference.arrayLen = 1;
  2012. /* "#ID1" */
  2013. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI_isUsed = 1;
  2014. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI.charactersLen = 4;
  2015. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI.characters[0] = '#';
  2016. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI.characters[1] = 'I';
  2017. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI.characters[2] = 'D';
  2018. exiXMLDSIG_SI.SignedInfo.Reference.array[0].URI.characters[3] = '1';
  2019. /* "http://www.w3.org/TR/canonical-exi/" */
  2020. exiXMLDSIG_SI.SignedInfo.Reference.array[0].Transforms_isUsed = 1;
  2021. exiXMLDSIG_SI.SignedInfo.Reference.array[0].Transforms.Transform.arrayLen = 1;
  2022. exiXMLDSIG_SI.SignedInfo.Reference.array[0].Transforms.Transform.array[0].Algorithm.charactersLen = 35;
  2023. strncpy(exiXMLDSIG_SI.SignedInfo.Reference.array[0].Transforms.Transform.array[0].Algorithm.characters, arrayCanonicalEXI, 35); /* Will copy 35 characters from arrayCanonicalEXI to characters */
  2024. exiXMLDSIG_SI.SignedInfo.Reference.array[0].Transforms.Transform.array[0].XPath.arrayLen = 0;
  2025. exiXMLDSIG_SI.SignedInfo.Reference.array[0].DigestMethod.Algorithm.charactersLen = 39;
  2026. strncpy(exiXMLDSIG_SI.SignedInfo.Reference.array[0].DigestMethod.Algorithm.characters, arrayxmlencSHA256, 39);
  2027. /* "0bXgPQBlvuVrMXmERTBR61TKGPwOCRYXT4s8d6mPSqk=" --> 16 Bytes 536F6D652052616E646F6D2044617461 */
  2028. exiXMLDSIG_SI.SignedInfo.Reference.array[0].DigestValue.bytesLen = 32;
  2029. memcpy(exiXMLDSIG_SI.SignedInfo.Reference.array[0].DigestValue.bytes, digestValue, 32);
  2030. }
  2031. errn = encode_xmldsigExiFragment(&stream2, &exiXMLDSIG_SI);
  2032. if((*stream2.pos) != sizeIsoStream2) {
  2033. errn = -1;
  2034. printf("EXI2 stream length does not match !\n");
  2035. return errn;
  2036. } else {
  2037. for(i=0; i<sizeIsoStream2; i++) {
  2038. if(stream2.data[i] != isoStream2[i]) {
  2039. errn = -1;
  2040. printf("EXI2 stream does not match at position %d !\n", i);
  2041. return errn;
  2042. }
  2043. }
  2044. }
  2045. if(errn == 0) {
  2046. printf("XMLDSIG test passed\n");
  2047. } else {
  2048. printf("XMLDSIG test error %d!\n", errn);
  2049. }
  2050. return errn;
  2051. }
  2052. #endif /* DEPLOY_ISO_CODEC_FRAGMENT */
  2053. #endif /* DEPLOY_XMLDSIG_CODEC == SUPPORT_YES */
  2054. int main_example(int argc, char *argv[]) {
  2055. int errn = 0;
  2056. printf("+++ Start application handshake protocol example +++\n\n");
  2057. errn = appHandshake();
  2058. printf("+++ Terminate application handshake protocol example with errn = %d +++\n\n", errn);
  2059. if(errn != 0) {
  2060. printf("\n\nHandshake error %d!\n", errn);
  2061. return errn;
  2062. }
  2063. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  2064. printf("+++ Start V2G client / service example for charging (ISO1) +++\n\n");
  2065. errn = charging1();
  2066. printf("\n+++Terminate V2G Client / Service example for charging with errn = %d +++\n\n", errn);
  2067. if(errn != 0) {
  2068. printf("\n\ncharging error %d!\n", errn);
  2069. return errn;
  2070. }
  2071. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  2072. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  2073. printf("+++ Start V2G client / service example for charging (ISO2) +++\n\n");
  2074. errn = charging2();
  2075. printf("\n+++Terminate V2G Client / Service example for charging with errn = %d +++\n\n", errn);
  2076. if(errn != 0) {
  2077. printf("\n\ncharging error %d!\n", errn);
  2078. return errn;
  2079. }
  2080. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  2081. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  2082. printf("+++ Start simple DIN test +++\n");
  2083. errn = din_test();
  2084. printf("+++ Terminate simple DIN test with errn = %d +++\n\n", errn);
  2085. if(errn != 0) {
  2086. printf("\nDIN test error %d!\n", errn);
  2087. return errn;
  2088. }
  2089. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  2090. #if DEPLOY_XMLDSIG_CODEC == SUPPORT_YES
  2091. #if DEPLOY_ISO_CODEC_FRAGMENT == SUPPORT_YES
  2092. printf("+++ Start simple XMLDSIG test +++\n");
  2093. errn = xmldsig_test();
  2094. printf("+++ Terminate simple XMLDSIG test with errn = %d +++\n\n", errn);
  2095. if(errn != 0) {
  2096. printf("\nXMLDSIG test error %d!\n", errn);
  2097. return errn;
  2098. }
  2099. #endif /* DEPLOY_ISO_CODEC_FRAGMENT */
  2100. #endif /* DEPLOY_XMLDSIG_CODEC == SUPPORT_YES */
  2101. return errn;
  2102. }