├── .cproject
├── .gitignore
├── .project
├── LICENCE.txt
├── README.md
├── source
├── SoAd.c
├── SoAd.h
├── SoAd_Cbk.h
└── SoAd_Types.h
└── tests
└── cunit
├── Makefile
├── include
├── ComStack_Types.h
├── Compiler.h
├── Det.h
├── PduR_SoAd.h
├── Platform_Types.h
├── Std_Types.h
└── TcpIp.h
└── suite_1
├── SoAd_Cfg.h
└── main.c
/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | make
60 |
61 | all
62 | true
63 | true
64 | true
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | tests/cunit/*/CUnitAutomated-Listing.xml
2 | tests/cunit/*/CUnitAutomated-Results.xml
3 | tests/cunit/*/main
4 | tests/cunit/*/main.exe
5 | tests/cunit/*/main.d
6 | tests/cunit/*/main.dSYM
7 | /CUnitAutomated-Results.xml
8 | /CUnitAutomated-Listing.xml
9 | .settings
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | autosar-soad
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LICENCE.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | [This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.]
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 |
474 | Copyright (C)
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
489 |
490 | Also add information on how to contact you by electronic and paper mail.
491 |
492 | You should also get your employer (if you work as a programmer) or your
493 | school, if any, to sign a "copyright disclaimer" for the library, if
494 | necessary. Here is a sample; alter the names:
495 |
496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498 |
499 | , 1 April 1990
500 | Ty Coon, President of Vice
501 |
502 | That's all there is to it!
503 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #AUTOSAR - SoAd
2 |
3 | An implementation of the AUTOSAR SoAd module
4 |
5 | http://www.autosar.org/
6 |
7 |
--------------------------------------------------------------------------------
/source/SoAd.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | /**
19 | * @file
20 | * @ingroup SoAd
21 | */
22 |
23 | /**
24 | * @addgroup SoAd SoAd
25 | *
26 | * An implementation of the AUTOSAR SoAd module
27 | */
28 |
29 | #include "Std_Types.h"
30 | #include "ComStack_Types.h"
31 | #include "SoAd.h"
32 | #include "PduR_SoAd.h"
33 | #include
34 |
35 | #if(SOAD_CFG_ENABLE_DEVELOPMENT_ERROR == STD_ON)
36 | #include "Det.h"
37 | #define SOAD_DET_ERROR(api, error) Det_ReportError(SOAD_MODULEID, SOAD_INSTANCEID, api, error)
38 | #define SOAD_DET_CHECK_RET(check, api, error) \
39 | do { \
40 | if (!(check)) { \
41 | (void)Det_ReportError(SOAD_MODULEID \
42 | , SOAD_INSTANCEID \
43 | , api \
44 | , error); \
45 | return E_NOT_OK; \
46 | } \
47 | } while(0)
48 |
49 | #define SOAD_DET_CHECK_RET_0(check, api, error) \
50 | do { \
51 | if (!(check)) { \
52 | (void)Det_ReportError(SOAD_MODULEID \
53 | , SOAD_INSTANCEID \
54 | , api \
55 | , error); \
56 | return; \
57 | } \
58 | } while(0)
59 |
60 | #else
61 | #define SOAD_DET_ERROR(api, error)
62 | #define SOAD_DET_CHECK_RET(check, api, error)
63 | #define SOAD_DET_CHECK_RET_0(check, api)
64 | #endif
65 |
66 | const SoAd_ConfigType * SoAd_Config = NULL_PTR;
67 |
68 | typedef struct {
69 | TcpIp_SocketIdType socket_id;
70 | TcpIp_SockAddrStorageType remote;
71 | SoAd_SoConStateType state;
72 | boolean request_open;
73 | boolean request_close;
74 | boolean request_abort;
75 |
76 | const SoAd_SocketRouteType* rx_route;
77 | const SoAd_PduRouteType* tx_route;
78 | PduLengthType tx_remain;
79 | PduLengthType tx_available;
80 |
81 | } SoAd_SoConStatusType;
82 |
83 | typedef struct {
84 | TcpIp_SocketIdType socket_id;
85 | } SoAd_SoGrpStatusType;
86 |
87 | SoAd_SoConStatusType SoAd_SoConStatus[SOAD_CFG_CONNECTION_COUNT];
88 | SoAd_SoGrpStatusType SoAd_SoGrpStatus[SOAD_CFG_CONNECTIONGROUP_COUNT];
89 |
90 | static const uint32 SoAd_Ip6Any[] = {
91 | TCPIP_IP6ADDR_ANY,
92 | TCPIP_IP6ADDR_ANY,
93 | TCPIP_IP6ADDR_ANY,
94 | TCPIP_IP6ADDR_ANY
95 | };
96 |
97 | static void SoAd_SockAddrCopy(TcpIp_SockAddrStorageType* trg, const TcpIp_SockAddrType* src)
98 | {
99 | switch (src->domain) {
100 | case TCPIP_AF_INET:
101 | trg->inet = *(const TcpIp_SockAddrInetType*)src;
102 | break;
103 | case TCPIP_AF_INET6:
104 | trg->inet6 = *(const TcpIp_SockAddrInet6Type*)src;
105 | break;
106 | default:
107 | break;
108 | }
109 | }
110 |
111 | /**
112 | * @brief Check if a socket address contains any wildcards
113 | * @param[in] addr Socket address to check
114 | * @return TRUE if socket address contain any wildcards
115 | */
116 | static boolean SoAd_SockAddrWildcard(const TcpIp_SockAddrType* addr)
117 | {
118 | boolean res = FALSE;
119 | switch (addr->domain) {
120 | case TCPIP_AF_INET: {
121 | const TcpIp_SockAddrInetType* inet = (const TcpIp_SockAddrInetType*)addr;
122 | if (inet->addr[0] == TCPIP_IPADDR_ANY) {
123 | res = TRUE;
124 | }
125 |
126 | if (inet->port == TCPIP_PORT_ANY) {
127 | res = TRUE;
128 | }
129 | }
130 | break;
131 | case TCPIP_AF_INET6: {
132 | const TcpIp_SockAddrInet6Type* inet6 = (const TcpIp_SockAddrInet6Type*)addr;
133 | if (memcmp(inet6->addr, SoAd_Ip6Any, sizeof(SoAd_Ip6Any)) == 0) {
134 | res = TRUE;
135 | }
136 |
137 | if (inet6->port == TCPIP_PORT_ANY) {
138 | res = TRUE;
139 | }
140 | }
141 | break;
142 | default:
143 | break;
144 | }
145 | return res;
146 | }
147 |
148 |
149 | /**
150 | * @brief Check if a socket address contains any wildcards
151 | * @param[in] addr Socket address to check
152 | * @return TRUE if socket address contain any wildcards
153 | */
154 | static boolean SoAd_SockAddrWildcardMatch(const TcpIp_SockAddrType* addr_mask, const TcpIp_SockAddrType* addr_check)
155 | {
156 | boolean res = FALSE;
157 | if (addr_mask->domain == addr_check->domain) {
158 | switch (addr_mask->domain) {
159 | case TCPIP_AF_INET: {
160 | const TcpIp_SockAddrInetType* inet_mask = (const TcpIp_SockAddrInetType*)addr_mask;
161 | const TcpIp_SockAddrInetType* inet_check = (const TcpIp_SockAddrInetType*)addr_check;
162 |
163 | if ((inet_mask->addr[0] == TCPIP_IPADDR_ANY)
164 | || (inet_mask->addr[0] == inet_check->addr[0])) {
165 | if ((inet_mask->port == TCPIP_PORT_ANY)
166 | || (inet_mask->port == inet_check->port)) {
167 | res = TRUE;
168 | }
169 | }
170 | }
171 | break;
172 | case TCPIP_AF_INET6: {
173 | const TcpIp_SockAddrInet6Type* inet_mask = (const TcpIp_SockAddrInet6Type*)addr_mask;
174 | const TcpIp_SockAddrInet6Type* inet_check = (const TcpIp_SockAddrInet6Type*)addr_check;
175 |
176 | if ((memcmp(SoAd_Ip6Any , inet_check->addr, sizeof(inet_check->addr)) == sizeof(inet_check->addr))
177 | || (memcmp(inet_mask->addr, inet_check->addr, sizeof(inet_check->addr)) == sizeof(inet_check->addr))) {
178 | if ((inet_mask->port == TCPIP_PORT_ANY)
179 | || (inet_mask->port == inet_check->port)) {
180 | res = TRUE;
181 | }
182 | }
183 | }
184 | break;
185 | default:
186 | res = E_NOT_OK;
187 | break;
188 | }
189 | } else {
190 | res = E_NOT_OK;
191 | }
192 | return res;
193 | }
194 |
195 |
196 | static void SoAd_Init_SoCon(SoAd_SoConIdType id)
197 | {
198 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
199 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
200 |
201 | memset(status, 0, sizeof(*status));
202 | if (config->remote) {
203 | SoAd_SockAddrCopy(&status->remote, config->remote);
204 | } else {
205 | status->remote.base.domain = (TcpIp_DomainType)0u;
206 | }
207 | status->socket_id = TCPIP_SOCKETID_INVALID;
208 |
209 | /** @req SWS_SoAd_00723 */
210 | status->state = SOAD_SOCON_OFFLINE;
211 | }
212 |
213 | static void SoAd_Init_SoGrp(SoAd_SoGrpIdType id)
214 | {
215 | const SoAd_SoGrpConfigType* config = SoAd_Config->groups[id];
216 | SoAd_SoGrpStatusType* status = &SoAd_SoGrpStatus[id];
217 | memset(status, 0, sizeof(*status));
218 | status->socket_id = TCPIP_SOCKETID_INVALID;
219 | }
220 |
221 | static Std_ReturnType SoAd_SoCon_Lookup(SoAd_SoConIdType *id, TcpIp_SocketIdType socket_id)
222 | {
223 | Std_ReturnType res = E_NOT_OK;
224 | SoAd_SoConIdType index;
225 | for (index = 0u; index < SOAD_CFG_CONNECTION_COUNT; ++index) {
226 | if (SoAd_SoConStatus[index].socket_id == socket_id) {
227 | res = E_OK;
228 | *id = index;
229 | break;
230 | }
231 | }
232 | return res;
233 | }
234 |
235 | static Std_ReturnType SoAd_SoGrp_Lookup(SoAd_SoGrpIdType *id, TcpIp_SocketIdType socket_id)
236 | {
237 | Std_ReturnType res = E_NOT_OK;
238 | SoAd_SoConIdType index;
239 | for (index = 0u; index < SOAD_CFG_CONNECTIONGROUP_COUNT; ++index) {
240 | if (SoAd_SoGrpStatus[index].socket_id == socket_id) {
241 | res = E_OK;
242 | *id = index;
243 | break;
244 | }
245 | }
246 | return res;
247 | }
248 |
249 | static Std_ReturnType SoAd_SoCon_Lookup_FreeSocket(
250 | SoAd_SoConIdType* id,
251 | SoAd_SoGrpIdType group,
252 | const TcpIp_SockAddrType* remote
253 | )
254 | {
255 | Std_ReturnType res = E_NOT_OK;
256 | SoAd_SoConIdType index;
257 | for (index = 0u; index < SOAD_CFG_CONNECTION_COUNT; ++index) {
258 | const SoAd_SoConConfigType* config = SoAd_Config->connections[index];
259 | const SoAd_SoConStatusType* status = &SoAd_SoConStatus[index];
260 |
261 | if (status->socket_id != TCPIP_SOCKETID_INVALID) {
262 | continue;
263 | }
264 |
265 | if (status->state != SOAD_SOCON_OFFLINE) {
266 | if (config->group == group) {
267 | if (SoAd_SockAddrWildcardMatch((TcpIp_SockAddrType*)&status->remote, remote) == TRUE) {
268 | res = E_OK;
269 | *id = index;
270 | break;
271 | }
272 | }
273 | }
274 | }
275 | return res;
276 | }
277 |
278 | static void SoAd_SoCon_EnterState(SoAd_SoConIdType id, SoAd_SoConStateType);
279 |
280 | void SoAd_Init(const SoAd_ConfigType* config)
281 | {
282 | uint16 id;
283 |
284 | SoAd_Config = config;
285 |
286 |
287 | /** @req SWS_SoAd_00723 */
288 | for (id = 0u; id < SOAD_CFG_CONNECTION_COUNT; ++id) {
289 | SoAd_Init_SoCon(id);
290 | }
291 |
292 | for (id = 0u; id < SOAD_CFG_CONNECTIONGROUP_COUNT; ++id) {
293 | SoAd_Init_SoGrp(id);
294 | }
295 | }
296 |
297 | static Std_ReturnType SoAd_GetSocketRoute(SoAd_SoConIdType con_id, uint32 header_id, SoAd_SocketRouteIdType* route_id)
298 | {
299 | Std_ReturnType res;
300 | const SoAd_SoConConfigType* con_config = SoAd_Config->connections[con_id];
301 | const SoAd_SoGrpConfigType* grp_config = SoAd_Config->groups[con_config->group];
302 |
303 | /* TODO - there can be multiple routes mapped to each connection */
304 | if (con_config->socket_route_id != SOAD_SOCKETROUTEID_INVALID) {
305 | *route_id = con_config->socket_route_id;
306 | res = E_OK;
307 | } else if (grp_config->socket_route_id < SOAD_SOCKETROUTEID_INVALID) {
308 | *route_id = grp_config->socket_route_id;
309 | res = E_OK;
310 | } else {
311 | res = E_NOT_OK;
312 | }
313 | return res;
314 | }
315 |
316 | static Std_ReturnType SoAd_GetPduRoute(PduIdType id, const SoAd_PduRouteType** route)
317 | {
318 | Std_ReturnType res;
319 | PduIdType high = SOAD_CFG_PDUROUTE_COUNT - 1u;
320 | PduIdType low = 0u;
321 |
322 | while (low < high) {
323 | PduIdType mid = low + (PduIdType)((high - low) >> 1u);
324 | if (SoAd_Config->pdu_routes[mid]->pdu_id < id) {
325 | low = mid + 1u;
326 | } else {
327 | low = mid;
328 | }
329 | }
330 |
331 | if (SoAd_Config->pdu_routes[low]->pdu_id == id) {
332 | *route = SoAd_Config->pdu_routes[low];
333 | res = E_OK;
334 | } else {
335 | res = E_NOT_OK;
336 | }
337 | return res;
338 | }
339 |
340 | /**
341 | * @brief Performs check to see if socket should go online
342 | * @req SWS_SoAd_00592
343 | */
344 | static void SoAd_RxIndication_RemoteOnline(SoAd_SoConIdType con_id, const TcpIp_SockAddrType* remote, TcpIp_SockAddrStorageType* restore, SoAd_SoConStateType* state)
345 | {
346 | SoAd_SoConStatusType* con_status = &SoAd_SoConStatus[con_id];
347 |
348 | *state = con_status->state;
349 | if (con_status->state != SOAD_SOCON_ONLINE) {
350 | const SoAd_SoConConfigType* con_config = SoAd_Config->connections[con_id];
351 | const SoAd_SoGrpConfigType* grp_config = SoAd_Config->groups[con_config->group];
352 | if (grp_config->protocol == TCPIP_IPPROTO_UDP) {
353 | if (grp_config->listen_only == FALSE) {
354 | if (SoAd_SockAddrWildcard(&con_status->remote.base) == TRUE) {
355 | /* TODO - (4) SoAdSocketMsgAcceptanceFilterEnabled */
356 | /* TODO - (6) Acceptance policy */
357 | *restore = con_status->remote;
358 | SoAd_SockAddrCopy(&con_status->remote, remote);
359 | SoAd_SoCon_EnterState(con_id, SOAD_SOCON_ONLINE);
360 | }
361 | }
362 | }
363 | }
364 | }
365 |
366 | /**
367 | * @brief Revert remote address change if state mismatches
368 | * @req SWS_SoAd_00710
369 | */
370 | static void SoAd_RxIndication_RemoteRevert(SoAd_SoConIdType con_id, const TcpIp_SockAddrStorageType* remote, const SoAd_SoConStateType state)
371 | {
372 | SoAd_SoConStatusType* con_status = &SoAd_SoConStatus[con_id];
373 |
374 | if (con_status->state != state) {
375 | con_status->remote = *remote;
376 | SoAd_SoCon_EnterState(con_id, state);
377 | }
378 | }
379 |
380 | Std_ReturnType SoAd_RxIndication_SoCon(
381 | SoAd_SoConIdType con_id,
382 | uint8* buf,
383 | uint16 len
384 | )
385 | {
386 | PduInfoType info;
387 | const SoAd_SoConStatusType* con_sts = &SoAd_SoConStatus[con_id];
388 |
389 | /* TODO - header id handling */
390 |
391 |
392 | if (con_sts->rx_route) {
393 | PduLengthType buf_len;
394 |
395 | info.SduDataPtr = NULL_PTR;
396 | info.SduLength = 0u;
397 |
398 | if (con_sts->rx_route->destination.upper->copy_rx_data(
399 | con_sts->rx_route->destination.pdu
400 | , &info
401 | , &buf_len) != BUFREQ_OK) {
402 | return E_NOT_OK;
403 | }
404 |
405 | /* TODO check for internal buffer */
406 | if (buf_len < len) {
407 | return E_NOT_OK;
408 | }
409 |
410 |
411 | info.SduLength = len;
412 | info.SduDataPtr = buf;
413 |
414 | if (con_sts->rx_route->destination.upper->copy_rx_data(
415 | con_sts->rx_route->destination.pdu
416 | , &info
417 | , &buf_len) != BUFREQ_OK) {
418 | return E_NOT_OK;
419 | }
420 |
421 | }
422 |
423 | return E_OK;
424 | }
425 |
426 | void SoAd_RxIndication(
427 | TcpIp_SocketIdType socket_id,
428 | const TcpIp_SockAddrType* remote,
429 | uint8* buf,
430 | uint16 len
431 | )
432 | {
433 | SoAd_SoConIdType id_con;
434 | Std_ReturnType res;
435 |
436 | /**
437 | * @req SWS_SoAd_00264
438 | */
439 | SOAD_DET_CHECK_RET_0(SoAd_Config != NULL_PTR
440 | , SOAD_API_RXINDICATION
441 | , SOAD_E_NOTINIT);
442 |
443 | /**
444 | * @req SWS_SoAd_00264
445 | */
446 | SOAD_DET_CHECK_RET_0(remote != NULL_PTR
447 | , SOAD_API_RXINDICATION
448 | , SOAD_E_INV_ARG);
449 |
450 |
451 | res = SoAd_SoCon_Lookup(&id_con, socket_id);
452 | if (res != E_OK) {
453 | SoAd_SoGrpIdType id_grp;
454 | res = SoAd_SoGrp_Lookup(&id_grp, socket_id);
455 | if (res == E_OK) {
456 | res = SoAd_SoCon_Lookup_FreeSocket(&id_con, id_grp, remote);
457 | }
458 | }
459 |
460 | if (res == E_OK) {
461 | TcpIp_SockAddrStorageType revert_remote;
462 | SoAd_SoConStateType revert_state;
463 | SoAd_RxIndication_RemoteOnline(id_con, remote, &revert_remote, &revert_state);
464 |
465 | res = SoAd_RxIndication_SoCon(id_con, buf, len);
466 |
467 | if (res != E_OK) {
468 | SoAd_RxIndication_RemoteRevert(id_con, &revert_remote, revert_state);
469 | }
470 | } else {
471 | /**
472 | * @req SWS_SoAd_00267
473 | */
474 | SOAD_DET_ERROR(SOAD_API_RXINDICATION
475 | , SOAD_E_INV_SOCKETID);
476 | }
477 | }
478 |
479 | /**
480 | * @brief Close down a socket group
481 | *
482 | * @req SWS_SoAd_00646
483 | * @req SWS_SoAd_00643
484 | *
485 | * Specification is unclear on how to handle sockets
486 | * that are in RECONNECT state, ie for example all
487 | * child sockets of a listening group socket. This
488 | * implementation will close down all group sockets
489 | * if the "master" socket is lost.
490 | */
491 | static void SoAd_SoGrp_Close(SoAd_SoGrpIdType id_grp)
492 | {
493 | SoAd_SoConIdType id_con;
494 |
495 | const SoAd_SoGrpConfigType* config_grp = SoAd_Config->groups[id_con];
496 | SoAd_SoGrpStatusType* status_grp = &SoAd_SoGrpStatus[id_con];
497 | status_grp->socket_id = TCPIP_SOCKETID_INVALID;
498 |
499 | for (id_con = 0u; id_con < SOAD_CFG_CONNECTION_COUNT; ++id_con) {
500 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id_con];
501 | const SoAd_SoConStatusType* status = &SoAd_SoConStatus[id_con];
502 | if (config->group == id_grp && status->socket_id == TCPIP_SOCKETID_INVALID) {
503 | SoAd_SoCon_EnterState(id_con, SOAD_SOCON_OFFLINE);
504 | }
505 | }
506 | }
507 |
508 | void SoAd_TcpIpEvent(
509 | TcpIp_SocketIdType socket_id,
510 | TcpIp_EventType event
511 | )
512 | {
513 | SoAd_SoConIdType id_con;
514 | SoAd_SoGrpIdType id_grp;
515 | Std_ReturnType res;
516 |
517 | /**
518 | * @req SWS_SoAd_00276
519 | */
520 | SOAD_DET_CHECK_RET_0(SoAd_Config != NULL_PTR
521 | , SOAD_API_TCPIPEVENT
522 | , SOAD_E_NOTINIT);
523 |
524 |
525 | switch (event) {
526 | case TCPIP_TCP_FIN_RECEIVED:
527 | (void)TcpIp_Close(socket_id, FALSE);
528 | break;
529 |
530 | case TCPIP_TCP_RESET:
531 | case TCPIP_TCP_CLOSED:
532 | case TCPIP_UDP_CLOSED:
533 | res = SoAd_SoGrp_Lookup(&id_grp, socket_id);
534 | if (res == E_OK) {
535 | SoAd_SoGrp_Close(id_grp);
536 | } else {
537 | res = SoAd_SoCon_Lookup(&id_con, socket_id);
538 | if (res == E_OK) {
539 | SoAd_SoCon_EnterState(id_con, SOAD_SOCON_OFFLINE);
540 | } else {
541 | /**
542 | * @req SWS_SoAd_00277
543 | */
544 | SOAD_DET_ERROR(SOAD_API_TCPIPEVENT
545 | , SOAD_E_INV_SOCKETID);
546 | }
547 | }
548 | break;
549 | default:
550 | SOAD_DET_ERROR(SOAD_API_TCPIPEVENT
551 | , SOAD_E_INV_ARG);
552 | break;
553 | }
554 |
555 | }
556 |
557 | void SoAd_TxConfirmation(
558 | TcpIp_SocketIdType socket_id,
559 | uint16 len
560 | )
561 | {
562 | SoAd_SoConIdType id;
563 | Std_ReturnType res;
564 |
565 | res = SoAd_SoCon_Lookup(&id, socket_id);
566 | if (res == E_OK) {
567 |
568 | }
569 | }
570 |
571 | Std_ReturnType SoAd_TcpAccepted(
572 | TcpIp_SocketIdType socket_id,
573 | TcpIp_SocketIdType socket_id_connected,
574 | const TcpIp_SockAddrType* remote
575 | )
576 | {
577 | SoAd_SoGrpIdType id_group;
578 | Std_ReturnType res;
579 |
580 | res = SoAd_SoGrp_Lookup(&id_group, socket_id);
581 | if (res == E_OK) {
582 | const SoAd_SoGrpConfigType* group = SoAd_Config->groups[id_group];
583 | SoAd_SoConIdType id_connected;
584 |
585 | if (group->initiate == FALSE) {
586 | res = SoAd_SoCon_Lookup_FreeSocket(&id_connected, id_group, remote);
587 | if (res == E_OK) {
588 | SoAd_SoConStatusType* status_connected = &SoAd_SoConStatus[id_connected];
589 | status_connected->socket_id = socket_id_connected;
590 | SoAd_SockAddrCopy(&status_connected->remote, remote);
591 | SoAd_SoCon_EnterState(id_connected, SOAD_SOCON_ONLINE);
592 | }
593 | }
594 | }
595 |
596 | return res;
597 | }
598 |
599 | void SoAd_TcpConnected(
600 | TcpIp_SocketIdType socket_id
601 | )
602 | {
603 | SoAd_SoConIdType id;
604 | Std_ReturnType res;
605 |
606 | res = SoAd_SoCon_Lookup(&id, socket_id);
607 | if (res == E_OK) {
608 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
609 | const SoAd_SoGrpConfigType* group = SoAd_Config->groups[config->group];
610 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
611 |
612 | if (group->initiate) {
613 | if (status->state != SOAD_SOCON_ONLINE) {
614 | if (group->protocol == TCPIP_IPPROTO_TCP) {
615 | SoAd_SoCon_EnterState(id, SOAD_SOCON_ONLINE);
616 | }
617 | }
618 | }
619 | }
620 | }
621 |
622 | BufReq_ReturnType SoAd_CopyTxData(
623 | TcpIp_SocketIdType socket_id,
624 | uint8* buf,
625 | uint16 len
626 | )
627 | {
628 | Std_ReturnType res;
629 | BufReq_ReturnType res_buf;
630 | SoAd_SoConIdType id_con;
631 | res = SoAd_SoCon_Lookup(&id_con, socket_id);
632 | if (res == E_OK) {
633 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id_con];
634 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id_con];
635 | PduInfoType info;
636 |
637 | info.SduLength = len;
638 | info.SduDataPtr = buf;
639 |
640 | res_buf = status->tx_route->upper->copy_tx_data(status->tx_route->pdu_id
641 | , &info
642 | , NULL_PTR
643 | , &status->tx_available);
644 | if (res_buf == BUFREQ_OK) {
645 | status->tx_remain -= len;
646 | }
647 | } else {
648 | res_buf = BUFREQ_E_NOT_OK;
649 | }
650 |
651 | return res_buf;
652 | }
653 |
654 | Std_ReturnType SoAd_IfTransmit(
655 | PduIdType pdu_id,
656 | const PduInfoType* pdu_info
657 | )
658 | {
659 | Std_ReturnType res;
660 | const SoAd_PduRouteType* route;
661 |
662 | /**
663 | * @req SWS_SoAd_00213
664 | */
665 | SOAD_DET_CHECK_RET(SoAd_Config != NULL_PTR
666 | , SOAD_API_IFTRANSMIT
667 | , SOAD_E_NOTINIT);
668 |
669 | /**
670 | * @req SWS_SoAd_00214
671 | */
672 | SOAD_DET_CHECK_RET(pdu_id < SOAD_CFG_PDUROUTE_COUNT
673 | , SOAD_API_IFTRANSMIT
674 | , SOAD_E_INV_PDUID);
675 |
676 | /**
677 | * @req SWS_SoAd_00653-TODO
678 | */
679 |
680 | res = SoAd_GetPduRoute(pdu_id, &route);
681 |
682 | if (res == E_OK) {
683 | SoAd_SoConStatusType* status;
684 | const SoAd_SoConConfigType* config;
685 | const SoAd_SoGrpConfigType* group;
686 | Std_ReturnType res;
687 |
688 | status = &SoAd_SoConStatus[route->destination.connection];
689 | config = SoAd_Config->connections[route->destination.connection];
690 | group = SoAd_Config->groups[config->group];
691 |
692 | if (status->state == SOAD_SOCON_ONLINE) {
693 | switch(group->protocol) {
694 | case TCPIP_IPPROTO_UDP:
695 | res = TcpIp_UdpTransmit(status->socket_id
696 | , pdu_info->SduDataPtr
697 | , &status->remote.base
698 | , pdu_info->SduLength);
699 | break;
700 | case TCPIP_IPPROTO_TCP:
701 | res = TcpIp_TcpTransmit(status->socket_id
702 | , pdu_info->SduDataPtr
703 | , pdu_info->SduLength
704 | , TRUE);
705 | break;
706 | default:
707 | res = E_NOT_OK;
708 | break;
709 | }
710 | } else {
711 | res = E_NOT_OK;
712 | }
713 | }
714 | return res;
715 | }
716 |
717 |
718 | Std_ReturnType SoAd_TpTransmit(
719 | PduIdType pdu_id,
720 | const PduInfoType* pdu_info
721 | )
722 | {
723 | Std_ReturnType res;
724 | const SoAd_PduRouteType* route;
725 |
726 | /**
727 | * @req SWS_SoAd_00224
728 | */
729 | SOAD_DET_CHECK_RET(SoAd_Config != NULL_PTR
730 | , SOAD_API_TPTRANSMIT
731 | , SOAD_E_NOTINIT);
732 |
733 | /**
734 | * @req SWS_SoAd_00237
735 | */
736 | SOAD_DET_CHECK_RET(pdu_id < SOAD_CFG_PDUROUTE_COUNT
737 | , SOAD_API_TPTRANSMIT
738 | , SOAD_E_INV_PDUID);
739 |
740 | /**
741 | * @req SWS_SoAd_00650-TODO
742 | */
743 |
744 | res = SoAd_GetPduRoute(pdu_id, &route);
745 |
746 | if (res == E_OK) {
747 | SoAd_SoConStatusType* status;
748 | status = &SoAd_SoConStatus[route->destination.connection];
749 | status->tx_route = route;
750 | }
751 | return res;
752 | }
753 |
754 | /**
755 | * @brief SWS_SoAd_00642-TODO
756 | */
757 | void SoAd_SoCon_ProcessClose(SoAd_SoConIdType id)
758 | {
759 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
760 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
761 |
762 | if (status->request_close) {
763 | if (status->socket_id != TCPIP_SOCKETID_INVALID) {
764 | TcpIp_Close(status->socket_id, status->request_abort);
765 | }
766 | status->request_close = FALSE;
767 | }
768 | }
769 |
770 | void SoAd_SoCon_ProcessTransmit(SoAd_SoConIdType id)
771 | {
772 | SoAd_SoConStatusType* status;
773 | const SoAd_SoConConfigType* config;
774 | const SoAd_SoGrpConfigType* group;
775 | const SoAd_PduRouteType* route;
776 | Std_ReturnType res;
777 | BufReq_ReturnType res_buf;
778 | PduInfoType pdu_info;
779 |
780 | status = &SoAd_SoConStatus[id];
781 | config = SoAd_Config->connections[id];
782 | group = SoAd_Config->groups[config->group];
783 | route = status->tx_route;
784 |
785 | if (route) {
786 | pdu_info.SduDataPtr = NULL_PTR;
787 | pdu_info.SduLength = 0u;
788 |
789 | if (status->tx_available == 0u) {
790 | res_buf = route->upper->copy_tx_data(route->pdu_id, &pdu_info, NULL_PTR, &status->tx_available);
791 | } else {
792 | res_buf = BUFREQ_OK;
793 | }
794 |
795 | if (res_buf == BUFREQ_OK) {
796 | switch(group->protocol) {
797 | case TCPIP_IPPROTO_UDP:
798 | res = TcpIp_UdpTransmit(status->socket_id
799 | , NULL_PTR
800 | , &status->remote.base
801 | , status->tx_available);
802 | break;
803 | case TCPIP_IPPROTO_TCP:
804 | res = TcpIp_TcpTransmit(status->socket_id
805 | , NULL_PTR
806 | , status->tx_available
807 | , FALSE);
808 | break;
809 | default:
810 | res = E_NOT_OK;
811 | break;
812 | }
813 | } else if (res_buf == BUFREQ_E_BUSY) {
814 | res = E_OK;
815 | } else {
816 | res = E_NOT_OK;
817 | }
818 |
819 | if (status->tx_remain == 0u || (res != E_OK)) {
820 | /** TODO - SoAdSocketTcpImmediateTpTxConfirmation==FALSE */
821 | status->tx_route = NULL_PTR;
822 | status->tx_remain = 0u;
823 | status->tx_available = 0u;
824 | route->upper->tx_confirmation(route->pdu_id, res);
825 | }
826 | }
827 | }
828 |
829 | void SoAd_SoCon_State_Online(SoAd_SoConIdType id)
830 | {
831 | SoAd_SoCon_ProcessClose(id);
832 | SoAd_SoCon_ProcessTransmit(id);
833 | }
834 |
835 | void SoAd_SoCon_State_Reconnect(SoAd_SoConIdType id)
836 | {
837 | SoAd_SoCon_ProcessClose(id);
838 | }
839 |
840 | /**
841 | * Check if we perform an open on the socket
842 | * @req SWS_SoAd_00589
843 | * @todo TCPIP_IPADDR_STATE_ASSIGNED
844 | * @todo Only first socket of a tcp group should be opened
845 | */
846 | static Std_ReturnType SoAd_SoCon_CheckOpen(SoAd_SoConIdType id)
847 | {
848 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
849 | const SoAd_SoGrpConfigType* config_group = SoAd_Config->groups[config->group];
850 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
851 | SoAd_SoGrpStatusType* status_group = &SoAd_SoGrpStatus[config->group];
852 | Std_ReturnType res = E_NOT_OK;
853 |
854 | if (status->socket_id == TCPIP_SOCKETID_INVALID) {
855 | if ((config_group->automatic != FALSE) || (status->request_open != FALSE)) {
856 | if (status->remote.base.domain != (TcpIp_DomainType)0u) {
857 | res = E_OK;
858 | }
859 | }
860 | }
861 |
862 | return res;
863 | }
864 |
865 | /**
866 | * @brief open a socket
867 | * @req SWS_SoAd_00590
868 | * @req SWS_SoAd_00638
869 | * @todo SoAdSocketLocalAddressRef
870 | * @todo SWS_SoAd_00689 Socket parameters
871 | * @todo MaxChannels of socket group
872 | */
873 | static Std_ReturnType SoAd_SoCon_PerformOpen(SoAd_SoConIdType id)
874 | {
875 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
876 | const SoAd_SoGrpConfigType* config_group = SoAd_Config->groups[config->group];
877 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
878 | SoAd_SoGrpStatusType* status_group = &SoAd_SoGrpStatus[config->group];
879 | Std_ReturnType res;
880 | TcpIp_SocketIdType *socket_id;
881 |
882 | status->request_open = FALSE;
883 |
884 | /*
885 | * for initiating sockets, the connection itself needs a socket
886 | * for waiting sockets, it's the socket group that holds the socket
887 | */
888 | if (config_group->initiate) {
889 | socket_id = &status->socket_id;
890 | } else {
891 | socket_id = &status_group->socket_id;
892 | }
893 |
894 | if (*socket_id == TCPIP_SOCKETID_INVALID) {
895 | res = TcpIp_SoAdGetSocket(config_group->domain
896 | , config_group->protocol
897 | , socket_id);
898 | if (res == E_OK) {
899 | uint16 localport = config_group->localport;
900 | res = TcpIp_Bind(*socket_id
901 | , config_group->localaddr
902 | , &localport);
903 |
904 | if (res == E_OK) {
905 | if (config_group->protocol == TCPIP_IPPROTO_TCP) {
906 | if (config_group->initiate) {
907 | res = TcpIp_TcpConnect(*socket_id
908 | , &status->remote.base);
909 | } else {
910 | res = TcpIp_TcpListen(*socket_id
911 | , SOAD_CFG_CONNECTION_COUNT);
912 | }
913 | }
914 | }
915 |
916 | /* on failure, we must clean up the socket so will try again */
917 | if (res != E_OK) {
918 | TcpIp_Close(*socket_id, TRUE);
919 | *socket_id = TCPIP_SOCKETID_INVALID;
920 | }
921 | }
922 | } else {
923 | res = E_OK;
924 | }
925 |
926 | return res;
927 | }
928 |
929 | void SoAd_SoCon_State_Offline(SoAd_SoConIdType id)
930 | {
931 | const SoAd_SoConConfigType* config = SoAd_Config->connections[id];
932 | const SoAd_SoGrpConfigType* config_group = SoAd_Config->groups[config->group];
933 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
934 | Std_ReturnType res;
935 |
936 | res = SoAd_SoCon_CheckOpen(id);
937 | if (res == E_OK) {
938 | res = SoAd_SoCon_PerformOpen(id);
939 | if (res == E_OK) {
940 | if (config_group->protocol == TCPIP_IPPROTO_TCP) {
941 | SoAd_SoCon_EnterState(id, SOAD_SOCON_RECONNECT);
942 | } else if (config_group->protocol == TCPIP_IPPROTO_UDP) {
943 |
944 | /**
945 | * @req SWS_SoAd_00686
946 | * @req SWS_SoAd_00591
947 | *
948 | * SoAdSocketUdpListenOnly should possibly be checked here, but
949 | * it seems redundant based on the wildcard check
950 | */
951 |
952 | if (SoAd_SockAddrWildcard(&status->remote.base) == TRUE) {
953 | SoAd_SoCon_EnterState(id, SOAD_SOCON_RECONNECT);
954 | } else {
955 | SoAd_SoCon_EnterState(id, SOAD_SOCON_ONLINE);
956 | }
957 | }
958 | }
959 | }
960 | }
961 |
962 | static void SoAd_SoCon_EnterState(SoAd_SoConIdType id, SoAd_SoConStateType state)
963 | {
964 | const SoAd_SoConConfigType* con_config = SoAd_Config->connections[id];
965 | const SoAd_SoGrpConfigType* grp_config = SoAd_Config->groups[con_config->group];
966 | SoAd_SoConStatusType* con_status = &SoAd_SoConStatus[id];
967 | SoAd_SocketRouteIdType route_id;
968 |
969 | /* update connection state */
970 | switch(state) {
971 | case SOAD_SOCON_OFFLINE:
972 | con_status->socket_id = TCPIP_SOCKETID_INVALID;
973 |
974 | if (con_status->rx_route) {
975 | con_status->rx_route->destination.upper->rx_indication(
976 | con_status->rx_route->destination.pdu
977 | , E_OK);
978 | con_status->rx_route = NULL;
979 | }
980 |
981 | break;
982 |
983 | case SOAD_SOCON_RECONNECT:
984 | break;
985 |
986 | case SOAD_SOCON_ONLINE: {
987 |
988 | if (SoAd_GetSocketRoute(id, SOAD_PDUHEADERID_INVALID, &route_id) == E_OK) {
989 | const SoAd_SocketRouteType* route_config = SoAd_Config->socket_routes[route_id];
990 | PduLengthType len = 0u;
991 | PduInfoType info = {0u};
992 |
993 | if (route_config->destination.upper->start_of_reception(
994 | route_config->destination.pdu
995 | , &info
996 | , len
997 | , &len) == BUFREQ_OK) {
998 | con_status->rx_route = route_config;
999 | }
1000 | }
1001 | break;
1002 |
1003 |
1004 | break;
1005 | }
1006 | default:
1007 | break;
1008 | }
1009 |
1010 | con_status->state = state;
1011 | }
1012 |
1013 | void SoAd_SoCon_MainFunction(SoAd_SoConIdType id)
1014 | {
1015 | SoAd_SoConStatusType* status = &SoAd_SoConStatus[id];
1016 |
1017 | switch(status->state) {
1018 | case SOAD_SOCON_OFFLINE:
1019 | SoAd_SoCon_State_Offline(id);
1020 | break;
1021 | case SOAD_SOCON_RECONNECT:
1022 | SoAd_SoCon_State_Reconnect(id);
1023 | break;
1024 | case SOAD_SOCON_ONLINE:
1025 | SoAd_SoCon_State_Online(id);
1026 | break;
1027 | default:
1028 | break;
1029 | }
1030 | }
1031 |
1032 | void SoAd_MainFunction(void)
1033 | {
1034 | SoAd_SoConIdType id;
1035 | for (id = 0u; id < SOAD_CFG_CONNECTION_COUNT; ++id) {
1036 | SoAd_SoCon_MainFunction(id);
1037 | }
1038 | }
1039 |
--------------------------------------------------------------------------------
/source/SoAd.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | /**
19 | * @file
20 | * @ingroup SoAd
21 | */
22 |
23 | #ifndef SOAD_H_
24 | #define SOAD_H_
25 |
26 | #include "Std_Types.h"
27 | #include "ComStack_Types.h"
28 | #include "TcpIp.h"
29 | #include "SoAd_Cfg.h"
30 |
31 | #define SOAD_MODULEID 56u
32 | #define SOAD_INSTANCEID 0u
33 |
34 | /**
35 | * @brief Development Errors
36 | * @req SWS_SoAd_00101
37 | * @{
38 | */
39 |
40 | /**
41 | * @brief API service called before initializing the module
42 | */
43 | #define SOAD_E_NOTINIT 0x01u
44 |
45 | /**
46 | * @brief API service called with NULL pointer
47 | */
48 | #define SOAD_E_PARAM_POINTER 0x02u
49 |
50 | /**
51 | * @brief Invalid argument
52 | */
53 | #define SOAD_E_INV_ARG 0x03u
54 |
55 | /**
56 | * @brief No buffer space available
57 | */
58 | #define SOAD_E_NOBUFS 0x04u
59 |
60 | /**
61 | * @brief Unknown PduHeader ID
62 | */
63 | #define SOAD_E_INV_PDUHEADER_ID 0x05u
64 |
65 | /**
66 | * @brief Invalid PDU ID
67 | */
68 | #define SOAD_E_INV_PDUID 0x06u
69 |
70 | /**
71 | * @brief Invalid socket address
72 | */
73 | #define SOAD_E_INV_SOCKETID 0x07u
74 |
75 | /**
76 | * @brief Invalid configuration set selection
77 | */
78 | #define SOAD_E_INIT_FAILED 0x08u
79 |
80 | /**
81 | * @}
82 | */
83 |
84 |
85 |
86 | /**
87 | * @brief Service identifier
88 | * @{
89 | */
90 | #define SOAD_API_INIT 0x01u
91 | #define SOAD_API_IFTRANSMIT 0x03u
92 | #define SOAD_API_TPTRANSMIT 0x04u
93 | #define SOAD_API_RXINDICATION 0x12u
94 | #define SOAD_API_TCPIPEVENT 0x16u
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | typedef enum {
101 | SOAD_SOCON_OFFLINE,
102 | SOAD_SOCON_RECONNECT,
103 | SOAD_SOCON_ONLINE,
104 | } SoAd_SoConStateType;
105 |
106 | typedef uint8 SoAd_SoConIdType;
107 | typedef uint8 SoAd_SoGrpIdType;
108 | typedef uint8 SoAd_SocketRouteIdType;
109 |
110 | #define SOAD_SOCKETROUTEID_INVALID (SoAd_SocketRouteIdType)(-1)
111 | #define SOAD_PDUHEADERID_INVALID (uint32)(-1)
112 |
113 |
114 | typedef enum {
115 | SOAD_UPPER_LAYER_IF,
116 | SOAD_UPPER_LAYER_TP,
117 | } SoAd_UpperLayerType;
118 |
119 |
120 | typedef struct {
121 | BufReq_ReturnType (*start_of_reception)(
122 | PduIdType id,
123 | const PduInfoType* info,
124 | PduLengthType len,
125 | PduLengthType* buf_len
126 | );
127 |
128 | BufReq_ReturnType (*copy_rx_data)(
129 | PduIdType id,
130 | const PduInfoType* info,
131 | PduLengthType* len
132 | );
133 |
134 | void (*rx_indication)(
135 | PduIdType id,
136 | Std_ReturnType result
137 | );
138 | } SoAd_TpRxType;
139 |
140 | typedef struct {
141 | BufReq_ReturnType (*copy_tx_data)(
142 | PduIdType id,
143 | const PduInfoType* info,
144 | RetryInfoType* retry,
145 | PduLengthType* available
146 | );
147 |
148 | void (*tx_confirmation)(
149 | PduIdType id,
150 | Std_ReturnType result
151 | );
152 | } SoAd_TpTxType;
153 |
154 | typedef struct {
155 | const SoAd_TpRxType* upper;
156 | PduIdType pdu; /**< SoAdRxPduRef */
157 | } SoAd_SocketRouteDestType;
158 |
159 | typedef struct {
160 | uint32 header_id; /**< SoAdRxPduHeaderId */
161 | SoAd_SocketRouteDestType destination; /**< SoAdSocketRouteDest */
162 | } SoAd_SocketRouteType;
163 |
164 | typedef struct {
165 | uint16 localport; /**< SoAdSocketLocalPort */
166 | TcpIp_LocalAddrIdType localaddr; /**< SoAdSocketLocalAddressRef */
167 | TcpIp_DomainType domain; /**< domain of local interface */
168 | TcpIp_ProtocolType protocol;
169 | boolean automatic; /**< SoAdSocketAutomaticSoConSetup */
170 | boolean initiate; /**< SoAdSocketTcpInitiate */
171 | boolean listen_only; /**< SoAdSocketUdpListenOnly */
172 | boolean header; /**< SoAdPduHeaderEnable */
173 | SoAd_SocketRouteIdType socket_route_id;
174 | } SoAd_SoGrpConfigType;
175 |
176 | typedef struct {
177 | SoAd_SoGrpIdType group;
178 | const TcpIp_SockAddrType* remote;
179 | SoAd_SocketRouteIdType socket_route_id;
180 | } SoAd_SoConConfigType;
181 |
182 | typedef struct {
183 | uint32 header_id;
184 | SoAd_SoConIdType connection;
185 | } SoAd_PduRouteDestType;
186 |
187 | typedef struct {
188 | PduIdType pdu_id;
189 | const SoAd_TpTxType* upper;
190 | SoAd_PduRouteDestType destination;
191 | } SoAd_PduRouteType;
192 |
193 | typedef struct {
194 | const SoAd_SoGrpConfigType* groups [SOAD_CFG_CONNECTIONGROUP_COUNT];
195 | const SoAd_SoConConfigType* connections [SOAD_CFG_CONNECTION_COUNT];
196 | const SoAd_PduRouteType* pdu_routes [SOAD_CFG_PDUROUTE_COUNT];
197 | const SoAd_SocketRouteType* socket_routes[SOAD_CFG_SOCKETROUTE_COUNT];
198 | } SoAd_ConfigType;
199 |
200 | void SoAd_Init(const SoAd_ConfigType* config);
201 | void SoAd_MainFunction(void);
202 |
203 | Std_ReturnType SoAd_IfTransmit(
204 | PduIdType pdu_id,
205 | const PduInfoType* pdu_info
206 | );
207 |
208 | Std_ReturnType SoAd_TpTransmit(
209 | PduIdType pdu_id,
210 | const PduInfoType* pdu_info
211 | );
212 |
213 | #endif
214 |
--------------------------------------------------------------------------------
/source/SoAd_Cbk.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | /**
19 | * @file
20 | * @ingroup SoAd
21 | */
22 |
23 | #ifndef SOAD_CBK_H_
24 | #define SOAD_CBK_H_
25 |
26 | #include "Std_Types.h"
27 | #include "TcpIp.h"
28 | #include "ComStack_Types.h"
29 |
30 | void SoAd_RxIndication(
31 | TcpIp_SocketIdType socket_id,
32 | const TcpIp_SockAddrType* remote,
33 | uint8* buf,
34 | uint16 len
35 | );
36 |
37 | void SoAd_TcpIpEvent(
38 | TcpIp_SocketIdType socket_id,
39 | TcpIp_EventType event
40 | );
41 |
42 | void SoAd_TxConfirmation(
43 | TcpIp_SocketIdType socket_id,
44 | uint16 len
45 | );
46 |
47 | Std_ReturnType SoAd_TcpAccepted(
48 | TcpIp_SocketIdType socket_id,
49 | TcpIp_SocketIdType socket_id_connected,
50 | const TcpIp_SockAddrType* remote
51 | );
52 |
53 | void SoAd_TcpConnected(
54 | TcpIp_SocketIdType socket_id
55 | );
56 |
57 | BufReq_ReturnType SoAd_CopyTxData(
58 | TcpIp_SocketIdType socket_id,
59 | uint8* buf,
60 | uint16 len
61 | );
62 |
63 | #endif /* SOAD_CBK_H_ */
64 |
--------------------------------------------------------------------------------
/source/SoAd_Types.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | /**
19 | * @file
20 | * @ingroup SoAd
21 | */
22 |
23 | #ifndef SOAD_TYPES_H_
24 | #define SOAD_TYPES_H_
25 |
26 | #include "SoAd.h"
27 |
28 | #endif /* SOAD_TYPES_H_ */
29 |
--------------------------------------------------------------------------------
/tests/cunit/Makefile:
--------------------------------------------------------------------------------
1 | INCLUDES += ../../source/
2 | INCLUDES += include/
3 |
4 | VPATH = ../../source/
5 |
6 |
7 | TESTS = suite_1
8 |
9 | SOURCES = $(addsuffix /main.c,$(TESTS))
10 | OBJECTS = $(SOURCES:.c=.o)
11 | DEPS = $(SOURCES:.c=.d)
12 | BINS = $(SOURCES:.c=)
13 | XMLS = $(addsuffix /CUnitAutomated-Results.xml,$(TESTS))
14 |
15 | CFLAGS+=-MMD -g -std=c99 $(addprefix -I,$(INCLUDES))
16 | LDLIBS+= -lcunit
17 |
18 | %/main: %/main.c
19 | $(CC) $(CFLAGS) -I$* $< $(LDLIBS) -o $@
20 |
21 | %/CUnitAutomated-Results.xml: %/main
22 | cd $*; ./$(
24 | #include
25 | /*------------------------------------------------------------------------------
26 | * Published parameters
27 | *----------------------------------------------------------------------------*/
28 | /* Unknown module */
29 | #define PLATFORM_MODULE_ID 0
30 |
31 | /* vendor specific */
32 | #define PLATFORM_SW_MAJOR_VERSION 0
33 | #define PLATFORM_SW_MINOR_VERSION 0
34 | #define PLATFORM_SW_PATCH_VERSION 0
35 |
36 | /*complies with autosar release version */
37 | #define PLATFORM_AR_MAJOR_VERSION 2
38 | #define PLATFORM_AR_MINOR_VERSION 2
39 | #define PLATFORM_AR_PATCH_VERSION 2
40 |
41 |
42 | /*------------------------------------------------------------------------------
43 | * Types
44 | *----------------------------------------------------------------------------*/
45 |
46 | typedef _Bool boolean;
47 | typedef int8_t sint8;
48 | typedef uint8_t uint8;
49 |
50 | typedef int16_t sint16;
51 | typedef uint16_t uint16;
52 |
53 | typedef int32_t sint32;
54 | typedef uint32_t uint32;
55 |
56 | typedef int64_t sint64;
57 | typedef uint64_t uint64;
58 |
59 | typedef uint_least8_t uint8_least;
60 | typedef uint_least16_t uint16_least;
61 | typedef uint_least32_t uint32_least;
62 | typedef uint_least64_t uint64_least;
63 |
64 | typedef int_least8_t sint8_least;
65 | typedef int_least16_t sint16_least;
66 | typedef int_least32_t sint32_least;
67 | typedef int_least64_t sint64_least;
68 |
69 | typedef float float32;
70 | typedef long double float64;
71 |
72 | /*------------------------------------------------------------------------------
73 | * Defines
74 | *----------------------------------------------------------------------------*/
75 | #ifndef TRUE
76 | #define TRUE ((boolean) 1)
77 | #endif
78 |
79 | #ifndef FALSE
80 | #define FALSE ((boolean) 0)
81 | #endif
82 |
83 |
84 | #define CPU_TYPE_8 8
85 | #define CPU_TYPE_16 16
86 | #define CPU_TYPE_32 32
87 |
88 | #define MSB_FIRST 0
89 | #define LSB_FIRST 1
90 | #define HIGH_BYTE_FIRST 0
91 | #define LOW_BYTE_FIRST 1
92 |
93 | #define CPU_TYPE CPU_TYPE_32
94 | #define CPU_BIT_ORDER MSB_FIRST
95 | #define CPU_BYTE_ORDER HIGH_BYTE_FIRST
96 |
97 | #endif /*PLATFORM_TYPES_H_*/
98 |
--------------------------------------------------------------------------------
/tests/cunit/include/Std_Types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012 QRTECH AB Gothenburg Sweden. All Rights Reserved.
3 | *
4 | * This document is provided to you in a non-exclusive agreement, and
5 | * shall not without QRTECH AB’s written permission be copied, imparted
6 | * to a third party or be used for any other unauthorized purpose.
7 | * QRTECH retain the right to reuse or re-license for other purposes.
8 | *
9 | * The document is provided "AS IS", WITHOUT WARRANTY and is only
10 | * supported by QRTECH in its complete original distribution.
11 | *
12 | * QRTECH AB (http://www.qrtech.se)
13 | * Mejerigatan 1
14 | * 412 76 Göteborg
15 | * SWEDEN
16 | * Tel: +46 31 773 76 00
17 | *
18 | */
19 |
20 | #ifndef STD_TYPES_H_
21 | #define STD_TYPES_H_
22 |
23 | /****************************************************************************************
24 | * INCLUDES
25 | ***************************************************************************************/
26 | #include "Compiler.h"
27 | #include "Platform_Types.h"
28 | /***************************************************************************************
29 | * Defines
30 | ***************************************************************************************/
31 |
32 | /* BSW00348 */
33 | #ifndef STATUSTYPEDEFINED
34 | #define STATUSTYPEDEFINED
35 | typedef unsigned char StatusType;
36 | #define E_OK 0u
37 | #endif
38 |
39 | /* BSW00357 */
40 | #define E_NOT_OK 1u
41 | #define E_COM_ID 2
42 |
43 | /* STD007*/
44 | #define STD_HIGH 0x01u /* Physical state 5V or 3.3V */
45 | #define STD_LOW 0x00u /* Physical state 0V */
46 |
47 | /* STD013 */
48 | #define STD_ACTIVE 0x01u /* Logical state active */
49 | #define STD_IDLE 0x00u /* Logical state idle */
50 |
51 | /* STD010 */
52 | #define STD_ON 0x01u
53 | #define STD_OFF 0x00u
54 |
55 | /****************************************************************************************
56 | * MACROS
57 | ***************************************************************************************/
58 |
59 | /****************************************************************************************
60 | * DATA TYPES
61 | ***************************************************************************************/
62 | typedef uint16 Std_ReturnType;
63 |
64 | /* BSW00407 */
65 | typedef struct {
66 | uint16 VendorId;
67 | uint16 ModuleId;
68 | uint16 SwMajorVersion;
69 | uint16 SwMinorVersion;
70 | uint16 SwPatchVersion;
71 | } Std_VersionInfoType;
72 | /****************************************************************************************
73 | * GLOBAL FUNCTION PROTOTYPES
74 | ***************************************************************************************/
75 |
76 |
77 | /****************************************************************************************
78 | * END FILE
79 | ***************************************************************************************/
80 |
81 | #endif /*STD_TYPES_H_*/
82 |
--------------------------------------------------------------------------------
/tests/cunit/include/TcpIp.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | #ifndef TCPIP_H_
19 | #define TCPIP_H_
20 |
21 | #include "Std_Types.h"
22 |
23 | /**
24 | * @brief Protocol type used by a socket.
25 | * @req SWS_TCPIP_00010
26 | */
27 | typedef enum {
28 | TCPIP_IPPROTO_TCP = 0x06,
29 | TCPIP_IPPROTO_UDP = 0x11,
30 | } TcpIp_ProtocolType;
31 |
32 | /**
33 | * @brief TcpIp address families.
34 | * @req SWS_TCPIP_00009
35 | */
36 | typedef enum {
37 | TCPIP_AF_INET = 0x02,
38 | TCPIP_AF_INET6 = 0x1c,
39 | } TcpIp_DomainType;
40 |
41 | /**
42 | * @brief Specifies the TcpIp state for a specific EthIf controller.
43 | * @req SWS_TCPIP_00073
44 | */
45 | typedef enum {
46 | /**
47 | * TCP/IP stack state for a specific EthIf controller is
48 | * ONLINE, i.e. communication via at least one IP address is
49 | * possible.
50 | */
51 | TCPIP_STATE_ONLINE,
52 |
53 | /**
54 | * TCP/IP stack state for a specific EthIf controller is
55 | * ONHOLD, i.e. no communication is currently possible
56 | * (e.g. link down).
57 | */
58 | TCPIP_STATE_ONHOLD,
59 |
60 | /**
61 | * TCP/IP stack state for a specific EthIf controller is
62 | * OFFLINE, i.e. no communication is possible.
63 | */
64 | TCPIP_STATE_OFFLINE,
65 |
66 | /**
67 | * TCP/IP stack state for a specific EthIf controller is
68 | * STARTUP, i.e. IP address assignment in progress or
69 | * ready for manual start, communication is currently not
70 | * possible.
71 | */
72 | TCPIP_STATE_STARTUP,
73 |
74 | /* TCP/IP stack state for a specific EthIf controller is
75 | * SHUTDOWN, i.e. release of resources using the EthIf
76 | * controller, release of IP address assignment.
77 | */
78 | TCPIP_STATE_SHUTDOWN,
79 | } TcpIp_StateType;
80 |
81 | /**
82 | * @brief Specifies the state of local IP address assignment
83 | * @req SWS_TCPIP_00082
84 | */
85 | typedef enum {
86 | /**
87 | * local IP address is assigned
88 | */
89 | TCPIP_IPADDR_STATE_ASSIGNED,
90 |
91 | /**
92 | * local IP address is assigned, but cannot be used as the network is not active
93 | */
94 | TCPIP_IPADDR_STATE_ONHOLD,
95 |
96 | /**
97 | * local IP address is unassigned
98 | */
99 | TCPIP_IPADDR_STATE_UNASSIGNED,
100 | } TcpIp_IpAddrStateType;
101 |
102 | /**
103 | * @brief Events reported by TcpIp.
104 | * @req SWS_TCPIP_00031
105 | */
106 | typedef enum {
107 | /**
108 | * TCP connection was reset, TCP socket and all related resources have been released.
109 | */
110 | TCPIP_TCP_RESET,
111 |
112 | /**
113 | * TCP connection was closed successfully, TCP socket and all related resources have been released.
114 | */
115 | TCPIP_TCP_CLOSED,
116 |
117 | /**
118 | * A FIN signal was received on the TCP connection, TCP socket is still valid.
119 | */
120 | TCPIP_TCP_FIN_RECEIVED,
121 |
122 | /**
123 | * UDP socket and all related resources have been released.
124 | */
125 | TCPIP_UDP_CLOSED,
126 | } TcpIp_EventType;
127 |
128 | typedef enum {
129 | /**
130 | * operation completed successfully.
131 | */
132 | TCPIP_OK,
133 |
134 | /**
135 | * operation failed.
136 | */
137 | TCPIP_E_NOT_OK,
138 |
139 | /**
140 | * operation failed because of an ARP/NDP cache miss.
141 | */
142 | TCPIP_E_PHYS_ADDR_MISS,
143 | } TcpIp_ReturnType;
144 |
145 | /**
146 | * @brief Development Errors
147 | * @req SWS_TCPIP_00042
148 | * @{
149 | */
150 |
151 | /** @brief API service called before initializing the module */
152 | #define TCPIP_E_NOTINIT 0x01u
153 |
154 | /** @brief API service called with NULL pointer */
155 | #define TCPIP_E_PARAM_POINTER 0x02u
156 |
157 | /** @brief Invalid argument */
158 | #define TCPIP_E_INV_ARG 0x03u
159 |
160 | /** @brief no buffer space available */
161 | #define TCPIP_E_NOBUFS 0x04u
162 |
163 | /** @brief Message to long */
164 | #define TCPIP_E_MSGSIZE 0x07u
165 |
166 | /** @brief Protocol wrong type for socket */
167 | #define TCPIP_E_PROTOCOL 0x08u
168 |
169 | /** @brief Compatibility with AUTOSAR invalid doc */
170 | #define TCPIP_E_PROTOTYPE TCPIP_E_PROTOCOL
171 |
172 | /** @brief Address already in use */
173 | #define TCPIP_E_ADDRINUSE 0x09u
174 |
175 | /** @brief Can't assignt requested address */
176 | #define TCPIP_E_ADDRNOTAVAIL 0x0Au
177 |
178 | /** @brief Socket is already connected */
179 | #define TCPIP_E_ISCONN 0x0Bu
180 |
181 | /** @brief Socket is not connected */
182 | #define TCPIP_E_NOTCONN 0x0Cu
183 |
184 | /** @brief Protocol is not available */
185 | #define TCPIP_E_NOPROTOOPT 0x0Du
186 |
187 | /** @brief Address family not supported by protocol family */
188 | #define TCPIP_E_AFNOSUPPORT 0x0Eu
189 |
190 | /** @brief Invalid configuration set selection */
191 | #define TCPIP_E_INIT_FAILED 0x0Fu
192 |
193 | /**
194 | * @}
195 | */
196 |
197 | /**
198 | * @brief Service identifier
199 | * @{
200 | */
201 | #define TCPIP_API_INIT 0x01u
202 | #define TCPIP_API_GETVERSIONINFO 0x02u
203 | #define TCPIP_API_BIND 0x05u
204 | #define TCPIP_API_TCPCONNECT 0x06u
205 | #define TCPIP_API_TCPLISTEN 0x07u
206 | #define TCPIP_API_TCPRECEIVED 0x08u
207 | #define TCPIP_API_REQUESTCOMMODE 0x09u
208 | #define TCPIP_API_REQUESTADDRASSIGNMENT 0x0Au
209 | #define TCPIP_API_RELEASEIPADDRASSIGNMENT 0x0Bu
210 | #define TCPIP_API_RESETIPASSIGNMENT 0x1Bu
211 | #define TCPIP_API_ICMPTRANSMIT 0x0Cu
212 | #define TCPIP_API_ICMPV6TRANSMIT 0x18u
213 | #define TCPIP_API_DHCPREADOPTION 0x0Du
214 | #define TCPIP_API_DHCPV6READOPTION 0x19u
215 | #define TCPIP_API_DHCPWRITEOPTION 0x0Eu
216 | #define TCPIP_API_DHCPV6WRITEOPTION 0x1Au
217 | #define TCPIP_API_CHANGEPARAMETER 0x0Fu
218 | #define TCPIP_API_GETIPADDR 0x10u
219 | #define TCPIP_API_GETPHYSADDR 0x01u
220 | #define TCPIP_API_GETREMOTEPHYSADDR 0x16u
221 | #define TCPIP_API_UDPTRANSMIT 0x00u
222 | #define TCPIP_API_TCPTRANSMIT 0x13u
223 | #define TCPIP_API_RXINDICATION 0x04u
224 | #define TCPIP_API_MAINFUNCTION 0x15u
225 | #define TCPIP_API_GETSOCKET 0x03u
226 | /**
227 | * @}
228 | */
229 |
230 | /**
231 | * @brief Configuration data structure of the TcpIp module.
232 | * @req SWS_TCPIP_00067
233 | */
234 | typedef struct {
235 | uint8 dummy;
236 | } TcpIp_ConfigType;
237 |
238 | /**
239 | * @brief Generic structure used by APIs to specify an IP address. (A specific address
240 | * type can be derived from this structure via a cast to the specific struct type.)
241 | * @req SWS_TCPIP_00012
242 | */
243 | typedef struct {
244 | TcpIp_DomainType domain;
245 | } TcpIp_SockAddrType;
246 |
247 | /**
248 | * @brief This structure defines an IPv4 address type which can be derived from the generic
249 | * address structure via cast.
250 | * @req SWS_TCPIP_00013
251 | */
252 | typedef struct {
253 | union {
254 | TcpIp_SockAddrType base;
255 | TcpIp_DomainType domain;
256 | };
257 |
258 | uint16 port;
259 | uint32 addr[1];
260 | } TcpIp_SockAddrInetType;
261 |
262 |
263 | /**
264 | * @brief This structure defines an IPv4 address type which can be derived from the generic
265 | * address structure via cast.
266 | * @req SWS_TCPIP_00013
267 | */
268 | typedef struct {
269 | union {
270 | TcpIp_SockAddrType base;
271 | TcpIp_DomainType domain;
272 | };
273 |
274 | uint16 port;
275 | uint32 addr[4];
276 | } TcpIp_SockAddrInet6Type;
277 |
278 | typedef union {
279 | TcpIp_SockAddrType base;
280 | TcpIp_SockAddrInetType inet;
281 | TcpIp_SockAddrInet6Type inet6;
282 | } TcpIp_SockAddrStorageType;
283 |
284 | /**
285 | * @brief socket identifier type for unique identification of a TcpIp stack socket.
286 | * TCPIP_SOCKETID_INVALID shall specify an invalid socket handle.
287 | * @req SWS_TCPIP_00038
288 | */
289 | typedef uint16 TcpIp_SocketIdType;
290 |
291 | /**
292 | * @brief Address identification type for unique identification of a local IP address and
293 | * EthIf Controller configured in the TcpIp module.
294 | * @req SWS_TCPIP_00030
295 | */
296 | typedef uint8 TcpIp_LocalAddrIdType;
297 |
298 | #define TCPIP_IPADDR_ANY 0x0u
299 | #define TCPIP_IP6ADDR_ANY 0x0u
300 | #define TCPIP_PORT_ANY 0x0u
301 | #define TCPIP_SOCKETID_INVALID (TcpIp_SocketIdType)0xffffu
302 | #define TCPIP_LOCALADDRID_ANY (TcpIp_LocalAddrIdType)0xffu
303 | /**
304 | * @brief By this API service the TCP/IP stack is requested to allocate a new socket.
305 | * Note: Each accepted incoming TCP connection also allocates a socket resource.
306 | */
307 | Std_ReturnType TcpIp_SoAdGetSocket(
308 | TcpIp_DomainType domain,
309 | TcpIp_ProtocolType protocol,
310 | TcpIp_SocketIdType* id
311 | );
312 |
313 | void TcpIp_Init(
314 | const TcpIp_ConfigType* config
315 | );
316 |
317 |
318 | Std_ReturnType TcpIp_Bind(
319 | TcpIp_SocketIdType id,
320 | TcpIp_LocalAddrIdType local,
321 | uint16* port
322 | );
323 |
324 | Std_ReturnType TcpIp_TcpListen(
325 | TcpIp_SocketIdType id,
326 | uint16 channels
327 | );
328 |
329 | Std_ReturnType TcpIp_TcpConnect(
330 | TcpIp_SocketIdType id,
331 | const TcpIp_SockAddrType* remote
332 | );
333 |
334 | Std_ReturnType TcpIp_UdpTransmit(
335 | TcpIp_SocketIdType id,
336 | const uint8* data,
337 | const TcpIp_SockAddrType* remote,
338 | uint16 len
339 | );
340 |
341 | Std_ReturnType TcpIp_TcpTransmit(
342 | TcpIp_SocketIdType id,
343 | const uint8* data,
344 | uint32 aailable,
345 | boolean force
346 | );
347 |
348 | Std_ReturnType TcpIp_TcpReceived(
349 | TcpIp_SocketIdType id,
350 | uint32 len
351 | );
352 |
353 | Std_ReturnType TcpIp_Close(
354 | TcpIp_SocketIdType id,
355 | boolean abort
356 | );
357 |
358 | #endif /* TCPIP_H_ */
359 |
--------------------------------------------------------------------------------
/tests/cunit/suite_1/SoAd_Cfg.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | #ifndef SOAD_CFG_H_
19 | #define SOAD_CFG_H_
20 |
21 | #include "Std_Types.h"
22 |
23 | #define SOAD_CFG_ENABLE_DEVELOPMENT_ERROR STD_ON
24 |
25 | #define SOAD_CFG_SOCKETROUTE_COUNT 3u
26 | #define SOAD_CFG_PDUROUTE_COUNT 1u
27 | #define SOAD_CFG_CONNECTIONGROUP_COUNT 3u
28 | #define SOAD_CFG_CONNECTION_COUNT 5u
29 |
30 | #endif /* SOAD_CFG_H_ */
31 |
--------------------------------------------------------------------------------
/tests/cunit/suite_1/main.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2015 Joakim Plate
2 | *
3 | * This library is free software; you can redistribute it and/or
4 | * modify it under the terms of the GNU Lesser General Public
5 | * License as published by the Free Software Foundation; either
6 | * version 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | * Lesser General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU Lesser General Public
14 | * License along with this library; if not, write to the Free Software
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 | */
17 |
18 | #include "SoAd.c"
19 |
20 | #include "CUnit/Basic.h"
21 | #include "CUnit/Automated.h"
22 |
23 | struct suite_socket_state {
24 | boolean retrieve;
25 | boolean bound;
26 | boolean listen;
27 | boolean connect;
28 | };
29 |
30 | struct suite_rxpdu_state {
31 | boolean rx_tp_active;
32 | uint32 rx_count;
33 | };
34 |
35 | struct suite_state {
36 | TcpIp_SocketIdType socket_id;
37 | uint16 port_index;
38 |
39 | struct suite_socket_state sockets[100];
40 | struct suite_rxpdu_state rxpdu[100];
41 | };
42 |
43 | struct suite_state suite_state;
44 |
45 | Std_ReturnType Det_ReportError(
46 | uint16 ModuleId,
47 | uint8 InstanceId,
48 | uint8 ApiId,
49 | uint8 ErrorId
50 | )
51 | {
52 | CU_ASSERT_EQUAL(ModuleId , SOAD_MODULEID);
53 | CU_ASSERT_EQUAL(InstanceId, 0u);
54 | CU_ASSERT_TRUE(FALSE);
55 | return E_OK;
56 | }
57 |
58 | Std_ReturnType TcpIp_SoAdGetSocket(
59 | TcpIp_DomainType domain,
60 | TcpIp_ProtocolType protocol,
61 | TcpIp_SocketIdType* id
62 | )
63 | {
64 | *id = ++suite_state.socket_id;
65 | suite_state.sockets[*id].retrieve = TRUE;
66 | return E_OK;
67 | }
68 |
69 |
70 | Std_ReturnType TcpIp_UdpTransmit(
71 | TcpIp_SocketIdType id,
72 | const uint8* data,
73 | const TcpIp_SockAddrType* remote,
74 | uint16 len
75 | )
76 | {
77 | return E_OK;
78 | }
79 |
80 | Std_ReturnType TcpIp_TcpTransmit(
81 | TcpIp_SocketIdType id,
82 | const uint8* data,
83 | uint32 aailable,
84 | boolean force
85 | )
86 | {
87 | return E_OK;
88 | }
89 |
90 | Std_ReturnType TcpIp_TcpReceived(
91 | TcpIp_SocketIdType id,
92 | uint32 len
93 | )
94 | {
95 | return E_OK;
96 | }
97 |
98 | Std_ReturnType TcpIp_Bind(
99 | TcpIp_SocketIdType id,
100 | TcpIp_LocalAddrIdType local,
101 | uint16* port
102 | )
103 | {
104 | if (port == TCPIP_PORT_ANY) {
105 | *port = ++suite_state.port_index;
106 | }
107 | suite_state.sockets[id].bound = TRUE;
108 | return E_OK;
109 | }
110 |
111 | Std_ReturnType TcpIp_TcpListen(
112 | TcpIp_SocketIdType id,
113 | uint16 channels
114 | )
115 | {
116 | suite_state.sockets[id].listen = TRUE;
117 | return E_OK;
118 | }
119 |
120 | Std_ReturnType TcpIp_TcpConnect(
121 | TcpIp_SocketIdType id,
122 | const TcpIp_SockAddrType* remote
123 | )
124 | {
125 | suite_state.sockets[id].connect = TRUE;
126 | return E_OK;
127 | }
128 |
129 |
130 | Std_ReturnType TcpIp_Close(
131 | TcpIp_SocketIdType id,
132 | boolean abort
133 | )
134 | {
135 | suite_state.sockets[id].connect = FALSE;
136 | suite_state.sockets[id].bound = FALSE;
137 | suite_state.sockets[id].listen = FALSE;
138 | suite_state.sockets[id].retrieve = FALSE;
139 | return E_OK;
140 | }
141 |
142 | void PduR_SoAdIfRxIndication(
143 | PduIdType id,
144 | const PduInfoType* info
145 | )
146 | {
147 | suite_state.rxpdu[id].rx_count += info->SduLength;
148 | }
149 |
150 | BufReq_ReturnType PduR_SoAdTpStartOfReception(
151 | PduIdType id,
152 | const PduInfoType* info,
153 | PduLengthType len,
154 | PduLengthType* buf_len
155 | )
156 | {
157 | suite_state.rxpdu[id].rx_tp_active = TRUE;
158 | suite_state.rxpdu[id].rx_count += info->SduLength;
159 | *buf_len = (PduLengthType)0xffffu;
160 | return E_OK;
161 | }
162 |
163 | BufReq_ReturnType PduR_SoAdTpCopyRxData(
164 | PduIdType id,
165 | const PduInfoType* info,
166 | PduLengthType* buf_len
167 | )
168 | {
169 | suite_state.rxpdu[id].rx_count += info->SduLength;
170 | *buf_len = (PduLengthType)0xffffu;
171 | return E_OK;
172 | }
173 |
174 | void PduR_SoAdTpRxIndication(
175 | PduIdType id,
176 | Std_ReturnType result
177 | )
178 | {
179 | suite_state.rxpdu[id].rx_tp_active = FALSE;
180 | }
181 |
182 | static BufReq_ReturnType PduR_SoAdIfStartOfReception(
183 | PduIdType id,
184 | const PduInfoType* info,
185 | PduLengthType len,
186 | PduLengthType* buf_len
187 | )
188 | {
189 | *buf_len = (PduLengthType)0xffffu;
190 | return BUFREQ_OK;
191 | }
192 |
193 | static BufReq_ReturnType PduR_SoAdIfCopyRxData(
194 | PduIdType id,
195 | const PduInfoType* info,
196 | PduLengthType* buf_len
197 | )
198 | {
199 | if (info->SduLength) {
200 | PduR_SoAdIfRxIndication(id, info);
201 | }
202 | *buf_len = (PduLengthType)0xffffu;
203 | return BUFREQ_OK;
204 | }
205 |
206 | static void PduR_SoAdTpRxIndication_If(
207 | PduIdType id,
208 | Std_ReturnType result
209 | )
210 | {
211 | }
212 |
213 | BufReq_ReturnType PduR_SoAdTpCopyTxData(
214 | PduIdType id,
215 | const PduInfoType* info,
216 | RetryInfoType* retry,
217 | PduLengthType* available
218 | )
219 | {
220 | return BUFREQ_OK;
221 | }
222 |
223 | void PduR_SoAdTpTxConfirmation(
224 | PduIdType id,
225 | Std_ReturnType result
226 | )
227 | {
228 | }
229 |
230 | #define SOCKET_GRP1 0
231 | #define SOCKET_GRP2 1
232 | #define SOCKET_GRP3 2
233 |
234 | #define SOCKET_GRP1_CON1 0
235 | #define SOCKET_GRP1_CON2 1
236 | #define SOCKET_GRP2_CON1 2
237 | #define SOCKET_GRP2_CON2 3
238 | #define SOCKET_GRP3_CON1 4
239 |
240 | #define SOCKET_ROUTE1 0
241 | #define SOCKET_ROUTE2 1
242 | #define SOCKET_ROUTE3 2
243 |
244 | const SoAd_TpRxType suite_tp = {
245 | .rx_indication = PduR_SoAdTpRxIndication,
246 | .copy_rx_data = PduR_SoAdTpCopyRxData,
247 | .start_of_reception = PduR_SoAdTpStartOfReception,
248 | };
249 |
250 | const SoAd_TpRxType suite_if = {
251 | .rx_indication = PduR_SoAdTpRxIndication_If,
252 | .copy_rx_data = PduR_SoAdIfCopyRxData,
253 | .start_of_reception = PduR_SoAdIfStartOfReception,
254 | };
255 |
256 | const SoAd_TpTxType suite_tptx = {
257 | .copy_tx_data = PduR_SoAdTpCopyTxData,
258 | .tx_confirmation = PduR_SoAdTpTxConfirmation,
259 | };
260 |
261 | const TcpIp_SockAddrInetType socket_remote_any_v4 = {
262 | .domain = TCPIP_AF_INET,
263 | .addr[0] = TCPIP_IPADDR_ANY,
264 | .port = TCPIP_PORT_ANY,
265 | };
266 |
267 | const TcpIp_SockAddrInetType socket_remote_loopback_v4 = {
268 | .domain = TCPIP_AF_INET,
269 | .addr[0] = 0x74000001,
270 | .port = 8000,
271 | };
272 |
273 | const SoAd_SoGrpConfigType socket_group_1 = {
274 | .localport = 8000,
275 | .localaddr = TCPIP_LOCALADDRID_ANY,
276 | .domain = TCPIP_AF_INET,
277 | .protocol = TCPIP_IPPROTO_TCP,
278 | .automatic = TRUE,
279 | .initiate = FALSE,
280 | .socket_route_id = SOAD_SOCKETROUTEID_INVALID
281 | };
282 |
283 | const SoAd_SoGrpConfigType socket_group_2 = {
284 | .localport = 8001,
285 | .localaddr = TCPIP_LOCALADDRID_ANY,
286 | .domain = TCPIP_AF_INET,
287 | .protocol = TCPIP_IPPROTO_UDP,
288 | .automatic = TRUE,
289 | .initiate = FALSE,
290 | .socket_route_id = SOAD_SOCKETROUTEID_INVALID
291 | };
292 |
293 | const SoAd_SoGrpConfigType socket_group_3 = {
294 | .localport = TCPIP_PORT_ANY,
295 | .localaddr = TCPIP_LOCALADDRID_ANY,
296 | .domain = TCPIP_AF_INET,
297 | .protocol = TCPIP_IPPROTO_TCP,
298 | .automatic = TRUE,
299 | .initiate = TRUE,
300 | .socket_route_id = SOAD_SOCKETROUTEID_INVALID
301 | };
302 |
303 | const SoAd_SocketRouteType socket_route_1 = {
304 | .header_id = SOAD_PDUHEADERID_INVALID,
305 | .destination = {
306 | .upper = &suite_tp,
307 | .pdu = 0u
308 | }
309 | };
310 |
311 | const SoAd_SocketRouteType socket_route_2 = {
312 | .header_id = SOAD_PDUHEADERID_INVALID,
313 | .destination = {
314 | .upper = &suite_if,
315 | .pdu = 1u
316 | }
317 | };
318 |
319 | const SoAd_SocketRouteType socket_route_3 = {
320 | .header_id = SOAD_PDUHEADERID_INVALID,
321 | .destination = {
322 | .upper = &suite_if,
323 | .pdu = 2u
324 | }
325 | };
326 |
327 | const SoAd_SoConConfigType socket_group_1_conn_1 = {
328 | .group = SOCKET_GRP1,
329 | .remote = (const TcpIp_SockAddrType*)&socket_remote_any_v4,
330 | .socket_route_id = SOCKET_ROUTE1,
331 | };
332 |
333 | const SoAd_SoConConfigType socket_group_1_conn_2 = {
334 | .group = SOCKET_GRP1,
335 | .remote = (const TcpIp_SockAddrType*)&socket_remote_any_v4,
336 | .socket_route_id = SOCKET_ROUTE1,
337 | };
338 |
339 | const SoAd_SoConConfigType socket_group_2_conn_1 = {
340 | .group = SOCKET_GRP2,
341 | .remote = (const TcpIp_SockAddrType*)&socket_remote_any_v4,
342 | .socket_route_id = SOCKET_ROUTE2,
343 | };
344 |
345 | const SoAd_SoConConfigType socket_group_2_conn_2 = {
346 | .group = SOCKET_GRP2,
347 | .remote = (const TcpIp_SockAddrType*)&socket_remote_any_v4,
348 | .socket_route_id = SOCKET_ROUTE2,
349 | };
350 |
351 | const SoAd_SoConConfigType socket_group_3_conn_1 = {
352 | .group = SOCKET_GRP3,
353 | .remote = (const TcpIp_SockAddrType*)&socket_remote_loopback_v4,
354 | .socket_route_id = SOCKET_ROUTE2,
355 | };
356 |
357 | const SoAd_PduRouteType pdu_route_1 = {
358 | .pdu_id = 0u,
359 | .upper = &suite_tptx,
360 | .destination = {
361 | .header_id = SOAD_PDUHEADERID_INVALID,
362 | .connection = SOCKET_GRP1_CON1,
363 | },
364 | };
365 |
366 | const SoAd_ConfigType config = {
367 | .groups = {
368 | [SOCKET_GRP1] = &socket_group_1,
369 | [SOCKET_GRP2] = &socket_group_2,
370 | [SOCKET_GRP3] = &socket_group_3,
371 | },
372 |
373 | .connections = {
374 | [SOCKET_GRP1_CON1] = &socket_group_1_conn_1,
375 | [SOCKET_GRP1_CON2] = &socket_group_1_conn_2,
376 | [SOCKET_GRP2_CON1] = &socket_group_2_conn_1,
377 | [SOCKET_GRP2_CON2] = &socket_group_2_conn_2,
378 | [SOCKET_GRP3_CON1] = &socket_group_3_conn_1,
379 | },
380 |
381 | .socket_routes = {
382 | [SOCKET_ROUTE1] = &socket_route_1,
383 | [SOCKET_ROUTE2] = &socket_route_2,
384 | [SOCKET_ROUTE3] = &socket_route_3,
385 | },
386 |
387 | .pdu_routes = {
388 | &pdu_route_1,
389 | },
390 | };
391 |
392 |
393 | int suite_init(void)
394 | {
395 | suite_state.socket_id = 1u;
396 | suite_state.port_index = 1024u;
397 | memset(suite_state.sockets, 0, sizeof(suite_state.sockets));
398 | memset(suite_state.rxpdu , 0, sizeof(suite_state.rxpdu));
399 |
400 | SoAd_Init(&config);
401 | return 0;
402 | }
403 |
404 | int suite_clean(void)
405 | {
406 | return 0;
407 | }
408 |
409 | void suite_test_wildcard_v4()
410 | {
411 | TcpIp_SockAddrInetType inet;
412 | inet.domain = TCPIP_AF_INET;
413 |
414 | inet.addr[0] = TCPIP_IPADDR_ANY;
415 | inet.port = TCPIP_PORT_ANY;
416 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
417 |
418 | inet.addr[0] = 1u;
419 | inet.port = TCPIP_PORT_ANY;
420 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
421 |
422 | inet.addr[0] = TCPIP_IPADDR_ANY;
423 | inet.port = 1u;
424 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
425 |
426 | inet.addr[0] = 1u;
427 | inet.port = 1u;
428 | CU_ASSERT_FALSE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
429 | }
430 |
431 | void suite_test_wildcard_v6()
432 | {
433 | TcpIp_SockAddrInet6Type inet;
434 | inet.domain = TCPIP_AF_INET6;
435 |
436 | inet.addr[0] = TCPIP_IPADDR_ANY;
437 | inet.addr[1] = TCPIP_IPADDR_ANY;
438 | inet.addr[2] = TCPIP_IPADDR_ANY;
439 | inet.addr[3] = TCPIP_IPADDR_ANY;
440 | inet.port = TCPIP_PORT_ANY;
441 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
442 |
443 | inet.addr[0] = TCPIP_IPADDR_ANY;
444 | inet.addr[1] = TCPIP_IPADDR_ANY;
445 | inet.addr[2] = TCPIP_IPADDR_ANY;
446 | inet.addr[3] = TCPIP_IPADDR_ANY;
447 | inet.port = 1u;
448 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
449 |
450 | inet.addr[0] = TCPIP_IPADDR_ANY;
451 | inet.addr[1] = 1u;
452 | inet.addr[2] = TCPIP_IPADDR_ANY;
453 | inet.addr[3] = TCPIP_IPADDR_ANY;
454 | inet.port = TCPIP_PORT_ANY;
455 | CU_ASSERT_TRUE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
456 |
457 | inet.addr[0] = TCPIP_IPADDR_ANY;
458 | inet.addr[1] = 1u;
459 | inet.addr[2] = TCPIP_IPADDR_ANY;
460 | inet.addr[3] = TCPIP_IPADDR_ANY;
461 | inet.port = 1u;
462 | CU_ASSERT_FALSE(SoAd_SockAddrWildcard((TcpIp_SockAddrType*)&inet));
463 | }
464 |
465 | void main_add_generic_suite(CU_pSuite suite)
466 | {
467 | CU_add_test(suite, "wildcard_v4" , suite_test_wildcard_v4);
468 | CU_add_test(suite, "wildcard_v6" , suite_test_wildcard_v6);
469 | }
470 |
471 | void main_test_mainfunction_open()
472 | {
473 | struct suite_socket_state* socket_state;
474 |
475 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP1_CON1].state, SOAD_SOCON_OFFLINE);
476 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP1_CON2].state, SOAD_SOCON_OFFLINE);
477 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP2_CON1].state, SOAD_SOCON_OFFLINE);
478 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP3_CON1].state, SOAD_SOCON_OFFLINE);
479 | SoAd_MainFunction();
480 |
481 | /* TCP listen socket should be bound and listening */
482 | CU_ASSERT_NOT_EQUAL_FATAL(SoAd_SoGrpStatus[SOCKET_GRP1].socket_id, TCPIP_SOCKETID_INVALID);
483 | socket_state = &suite_state.sockets[SoAd_SoGrpStatus[SOCKET_GRP1].socket_id];
484 | CU_ASSERT_EQUAL(socket_state->retrieve , TRUE);
485 | CU_ASSERT_EQUAL(socket_state->bound , TRUE);
486 | CU_ASSERT_EQUAL(socket_state->listen , TRUE);
487 | CU_ASSERT_EQUAL(socket_state->connect , FALSE);
488 |
489 | /* TCP extra sockets should be just waiting to connect */
490 | CU_ASSERT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP1_CON1].socket_id, TCPIP_SOCKETID_INVALID);
491 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP1_CON1].state, SOAD_SOCON_RECONNECT);
492 |
493 | CU_ASSERT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP1_CON2].socket_id, TCPIP_SOCKETID_INVALID);
494 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP1_CON2].state, SOAD_SOCON_RECONNECT);
495 |
496 | /* UDP group socket should be bound, but not listening or connected */
497 | CU_ASSERT_NOT_EQUAL_FATAL(SoAd_SoGrpStatus[SOCKET_GRP2].socket_id, TCPIP_SOCKETID_INVALID);
498 | socket_state = &suite_state.sockets[SoAd_SoGrpStatus[SOCKET_GRP2].socket_id];
499 | CU_ASSERT_EQUAL(socket_state->retrieve , TRUE);
500 | CU_ASSERT_EQUAL(socket_state->bound , TRUE);
501 | CU_ASSERT_EQUAL(socket_state->listen , FALSE);
502 | CU_ASSERT_EQUAL(socket_state->connect , FALSE);
503 |
504 | CU_ASSERT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP2_CON1].socket_id, TCPIP_SOCKETID_INVALID);
505 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP2_CON1].state, SOAD_SOCON_RECONNECT);
506 |
507 | /* TCP connect socket should be waiting for a connection */
508 | CU_ASSERT_NOT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP3_CON1].socket_id, TCPIP_SOCKETID_INVALID);
509 | socket_state = &suite_state.sockets[SoAd_SoConStatus[SOCKET_GRP3_CON1].socket_id];
510 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP3_CON1].state, SOAD_SOCON_RECONNECT);
511 | CU_ASSERT_EQUAL(socket_state->connect , TRUE);
512 | }
513 |
514 | void main_test_mainfunction_accept(SoAd_SoGrpIdType id_grp, SoAd_SoConIdType id_con)
515 | {
516 | TcpIp_SockAddrInetType inet;
517 | inet.domain = TCPIP_AF_INET;
518 | inet.addr[0] = 1;
519 | inet.port = 1;
520 |
521 | CU_ASSERT_EQUAL(SoAd_TcpAccepted(SoAd_SoGrpStatus[id_grp].socket_id
522 | , ++suite_state.socket_id
523 | , (TcpIp_SockAddrType*)&inet)
524 | , E_OK);
525 | CU_ASSERT_NOT_EQUAL_FATAL(SoAd_SoConStatus[id_con].socket_id
526 | , TCPIP_SOCKETID_INVALID);
527 |
528 | struct suite_socket_state* socket_state;
529 | socket_state = &suite_state.sockets[SoAd_SoConStatus[id_con].socket_id];
530 | CU_ASSERT_EQUAL(socket_state->retrieve , FALSE);
531 | CU_ASSERT_EQUAL(socket_state->bound , FALSE);
532 | CU_ASSERT_EQUAL(socket_state->listen , FALSE);
533 | CU_ASSERT_EQUAL(socket_state->connect , FALSE);
534 | CU_ASSERT_EQUAL(SoAd_SoConStatus[id_con].state
535 | , SOAD_SOCON_ONLINE);
536 | }
537 |
538 | void main_test_mainfunction_accept_1(void)
539 | {
540 | main_test_mainfunction_accept(SOCKET_GRP1, SOCKET_GRP1_CON1);
541 | }
542 |
543 | void main_test_mainfunction_accept_2(void)
544 | {
545 | main_test_mainfunction_accept(SOCKET_GRP1, SOCKET_GRP1_CON2);
546 | }
547 |
548 |
549 | void main_test_mainfunction_connect(SoAd_SoGrpIdType id_grp, SoAd_SoConIdType id_con)
550 | {
551 | TcpIp_SockAddrInetType inet;
552 | inet.domain = TCPIP_AF_INET;
553 | inet.addr[0] = 1;
554 | inet.port = 1;
555 |
556 | SoAd_TcpConnected(SoAd_SoConStatus[id_con].socket_id);
557 |
558 | CU_ASSERT_NOT_EQUAL_FATAL(SoAd_SoConStatus[id_con].socket_id
559 | , TCPIP_SOCKETID_INVALID);
560 |
561 | struct suite_socket_state* socket_state;
562 | socket_state = &suite_state.sockets[SoAd_SoConStatus[id_con].socket_id];
563 | CU_ASSERT_EQUAL(socket_state->retrieve , FALSE);
564 | CU_ASSERT_EQUAL(socket_state->bound , FALSE);
565 | CU_ASSERT_EQUAL(socket_state->listen , FALSE);
566 | CU_ASSERT_EQUAL(socket_state->connect , FALSE);
567 | CU_ASSERT_EQUAL(SoAd_SoConStatus[id_con].state
568 | , SOAD_SOCON_ONLINE);
569 | }
570 |
571 | void main_test_mainfunction_receive(SoAd_SoConIdType id_grp, SoAd_SoConIdType id_con)
572 | {
573 | TcpIp_SockAddrInetType inet;
574 | uint8 data[100];
575 | uint32 prev;
576 | const SoAd_SocketRouteType* route;
577 | TcpIp_SocketIdType socket_id;
578 |
579 | inet.domain = TCPIP_AF_INET;
580 | inet.addr[0] = 1;
581 | inet.port = id_con;
582 |
583 | route = config.socket_routes[config.connections[id_con]->socket_route_id];
584 | prev = suite_state.rxpdu[route->destination.pdu].rx_count;
585 |
586 | socket_id = SoAd_SoConStatus[id_con].socket_id;
587 | if (socket_id == TCPIP_SOCKETID_INVALID) {
588 | socket_id = SoAd_SoGrpStatus[id_grp].socket_id;
589 | }
590 |
591 | SoAd_RxIndication(socket_id
592 | , (TcpIp_SockAddrType*)&inet
593 | , data
594 | , sizeof(data));
595 |
596 | CU_ASSERT_EQUAL(suite_state.rxpdu[route->destination.pdu].rx_count, prev+sizeof(data));
597 | }
598 |
599 | void main_test_mainfunction_receive_udp_1()
600 | {
601 | CU_ASSERT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP2_CON1].state, SOAD_SOCON_RECONNECT);
602 | main_test_mainfunction_receive(SOCKET_GRP2, SOCKET_GRP2_CON1);
603 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP2_CON1].state, SOAD_SOCON_ONLINE);
604 | }
605 |
606 | void main_test_mainfunction_receive_udp_2()
607 | {
608 | CU_ASSERT_EQUAL_FATAL(SoAd_SoConStatus[SOCKET_GRP2_CON2].state, SOAD_SOCON_RECONNECT);
609 | main_test_mainfunction_receive(SOCKET_GRP2, SOCKET_GRP2_CON2);
610 | CU_ASSERT_EQUAL(SoAd_SoConStatus[SOCKET_GRP2_CON2].state, SOAD_SOCON_ONLINE);
611 | }
612 |
613 |
614 | void main_test_mainfunction_receive_tcp_1()
615 | {
616 | main_test_mainfunction_receive(SOCKET_GRP1, SOCKET_GRP1_CON1);
617 | }
618 |
619 | void main_test_mainfunction_receive_tcp_2()
620 | {
621 | main_test_mainfunction_receive(SOCKET_GRP1, SOCKET_GRP1_CON2);
622 | }
623 |
624 |
625 | void main_add_mainfunction_suite(CU_pSuite suite)
626 | {
627 | CU_add_test(suite, "open" , main_test_mainfunction_open);
628 | CU_add_test(suite, "accept_1" , main_test_mainfunction_accept_1);
629 | CU_add_test(suite, "accept_2" , main_test_mainfunction_accept_2);
630 | CU_add_test(suite, "receive_udp_1" , main_test_mainfunction_receive_udp_1);
631 | CU_add_test(suite, "receive_udp_2" , main_test_mainfunction_receive_udp_2);
632 | CU_add_test(suite, "receive_tcp_1" , main_test_mainfunction_receive_tcp_1);
633 | CU_add_test(suite, "receive_tcp_2" , main_test_mainfunction_receive_tcp_2);
634 | }
635 |
636 | int main(void)
637 | {
638 | CU_pSuite suite = NULL;
639 |
640 | /* initialize the CUnit test registry */
641 | if (CUE_SUCCESS != CU_initialize_registry())
642 | return CU_get_error();
643 |
644 | /* add a suite to the registry */
645 | suite = CU_add_suite("Suite_Generic", suite_init, suite_clean);
646 | main_add_generic_suite(suite);
647 |
648 | suite = CU_add_suite("Suite_MainFunction", suite_init, suite_clean);
649 | main_add_mainfunction_suite(suite);
650 |
651 |
652 | /* Run all tests using the CUnit Basic interface */
653 | CU_basic_set_mode(CU_BRM_VERBOSE);
654 | CU_basic_run_tests();
655 |
656 | /* Run results and output to files */
657 | CU_automated_run_tests();
658 | CU_list_tests_to_file();
659 |
660 | CU_cleanup_registry();
661 | return CU_get_error();
662 | }
663 |
--------------------------------------------------------------------------------