main_example.c 104 KB

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